|
import gradio as gr |
|
|
|
def create_policy_popup_app(): |
|
|
|
pdf_id = "1WZCQpIWfelbxgBr8dNiW2rqVGaDyf-Gi" |
|
embed_url = f"https://drive.google.com/file/d/{pdf_id}/preview" |
|
|
|
custom_css = """ |
|
.pdf-modal { |
|
display: none; |
|
position: fixed; |
|
z-index: 1000; |
|
left: 0; |
|
top: 0; |
|
width: 100%; |
|
height: 100%; |
|
background-color: rgba(0,0,0,0.7); |
|
overflow: auto; |
|
} |
|
|
|
.pdf-modal-content { |
|
background-color: white; |
|
margin: 2% auto; |
|
padding: 20px; |
|
width: 90%; |
|
max-width: 900px; |
|
height: 90%; |
|
box-shadow: 0 5px 15px rgba(0,0,0,0.3); |
|
border-radius: 8px; |
|
position: relative; |
|
} |
|
|
|
.close-btn { |
|
position: absolute; |
|
right: 15px; |
|
top: 15px; |
|
font-size: 24px; |
|
cursor: pointer; |
|
background: #222; |
|
color: white; |
|
border: none; |
|
border-radius: 4px; |
|
padding: 5px 15px; |
|
z-index: 1001; |
|
} |
|
|
|
.pdf-container { |
|
width: 100%; |
|
height: calc(100% - 40px); |
|
margin-top: 40px; |
|
} |
|
|
|
.pdf-embed { |
|
width: 100%; |
|
height: 100%; |
|
border: 1px solid #ddd; |
|
} |
|
""" |
|
|
|
modal_html = f""" |
|
<div id="pdfModal" class="pdf-modal"> |
|
<div class="pdf-modal-content"> |
|
<button class="close-btn" onclick="document.getElementById('pdfModal').style.display='none';document.body.style.overflow='auto';">Γ</button> |
|
<div class="pdf-container"> |
|
<iframe class="pdf-embed" src="{embed_url}" type="application/pdf"></iframe> |
|
</div> |
|
</div> |
|
</div> |
|
""" |
|
|
|
with gr.Blocks(css=custom_css) as app: |
|
gr.Markdown("## View Hate Speech Policy") |
|
gr.HTML(modal_html) |
|
|
|
open_button = gr.Button("π Open Policy Document") |
|
|
|
open_button.click( |
|
fn=lambda: None, |
|
inputs=None, |
|
outputs=None, |
|
js=""" |
|
() => { |
|
const modal = document.getElementById('pdfModal'); |
|
if (modal) { |
|
modal.style.display = 'block'; |
|
document.body.style.overflow = 'hidden'; |
|
} |
|
} |
|
""" |
|
) |
|
|
|
return app |
|
|
|
if __name__ == "__main__": |
|
app = create_policy_popup_app() |
|
app.launch() |