Upload folder using huggingface_hub
Browse files
test.py
CHANGED
@@ -1,27 +1,9 @@
|
|
1 |
import gradio as gr
|
2 |
-
import base64
|
3 |
import os
|
4 |
|
5 |
-
def
|
6 |
-
def get_pdf_base64():
|
7 |
-
pdf_path = "Hate Speech Policy.pdf"
|
8 |
-
if not os.path.exists(pdf_path):
|
9 |
-
print(f"Error: PDF file not found at {os.path.abspath(pdf_path)}")
|
10 |
-
return None
|
11 |
-
|
12 |
-
try:
|
13 |
-
with open(pdf_path, "rb") as pdf_file:
|
14 |
-
pdf_data = pdf_file.read()
|
15 |
-
base64_pdf = base64.b64encode(pdf_data).decode('utf-8')
|
16 |
-
return base64_pdf
|
17 |
-
except Exception as e:
|
18 |
-
print(f"Error reading PDF file: {str(e)}")
|
19 |
-
return None
|
20 |
-
|
21 |
-
pdf_base64 = get_pdf_base64()
|
22 |
-
|
23 |
modal_css = """
|
24 |
-
.
|
25 |
display: none;
|
26 |
position: fixed;
|
27 |
z-index: 1000;
|
@@ -32,8 +14,8 @@ def create_pdf_popup_app():
|
|
32 |
background-color: rgba(0,0,0,0.7);
|
33 |
overflow: auto;
|
34 |
}
|
35 |
-
|
36 |
-
.
|
37 |
background-color: white;
|
38 |
margin: 2% auto;
|
39 |
padding: 20px;
|
@@ -44,7 +26,7 @@ def create_pdf_popup_app():
|
|
44 |
border-radius: 8px;
|
45 |
position: relative;
|
46 |
}
|
47 |
-
|
48 |
.close-btn {
|
49 |
position: absolute;
|
50 |
right: 15px;
|
@@ -56,79 +38,66 @@ def create_pdf_popup_app():
|
|
56 |
border: none;
|
57 |
border-radius: 4px;
|
58 |
padding: 5px 15px;
|
59 |
-
z-index: 1001;
|
60 |
}
|
61 |
-
|
62 |
-
.
|
63 |
width: 100%;
|
64 |
height: calc(100% - 40px);
|
65 |
margin-top: 40px;
|
|
|
66 |
}
|
67 |
-
|
68 |
-
.
|
69 |
-
width: 100%;
|
70 |
-
height: 100%;
|
71 |
border: 1px solid #ddd;
|
72 |
-
|
73 |
-
|
74 |
-
.pdf-error {
|
75 |
-
text-align: center;
|
76 |
-
margin-top: 100px;
|
77 |
-
color: red;
|
78 |
-
font-size: 18px;
|
79 |
}
|
80 |
"""
|
81 |
|
82 |
-
|
83 |
-
|
84 |
-
<div
|
85 |
-
<
|
86 |
-
|
87 |
-
<
|
88 |
-
<iframe class="pdf-embed" src="data:application/pdf;base64,{pdf_base64}#toolbar=0&navpanes=0" type="application/pdf"></iframe>
|
89 |
-
</div>
|
90 |
</div>
|
91 |
</div>
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
104 |
|
105 |
with gr.Blocks(css=modal_css) as app:
|
106 |
-
gr.Markdown("
|
107 |
gr.HTML(modal_html)
|
108 |
-
|
109 |
-
gr.
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
modal.style.display = 'block';
|
117 |
-
document.body.style.overflow = 'hidden';
|
118 |
-
});
|
119 |
-
window.addEventListener('click', function(e) {
|
120 |
-
if (e.target === modal) {
|
121 |
-
modal.style.display = 'none';
|
122 |
-
document.body.style.overflow = 'auto';
|
123 |
-
}
|
124 |
-
});
|
125 |
-
}
|
126 |
-
});
|
127 |
-
</script>
|
128 |
-
""")
|
129 |
|
130 |
return app
|
131 |
|
132 |
if __name__ == "__main__":
|
133 |
-
app =
|
134 |
app.launch()
|
|
|
1 |
import gradio as gr
|
|
|
2 |
import os
|
3 |
|
4 |
+
def create_policy_image_modal_app():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
modal_css = """
|
6 |
+
.img-modal {
|
7 |
display: none;
|
8 |
position: fixed;
|
9 |
z-index: 1000;
|
|
|
14 |
background-color: rgba(0,0,0,0.7);
|
15 |
overflow: auto;
|
16 |
}
|
17 |
+
|
18 |
+
.img-modal-content {
|
19 |
background-color: white;
|
20 |
margin: 2% auto;
|
21 |
padding: 20px;
|
|
|
26 |
border-radius: 8px;
|
27 |
position: relative;
|
28 |
}
|
29 |
+
|
30 |
.close-btn {
|
31 |
position: absolute;
|
32 |
right: 15px;
|
|
|
38 |
border: none;
|
39 |
border-radius: 4px;
|
40 |
padding: 5px 15px;
|
|
|
41 |
}
|
42 |
+
|
43 |
+
.img-container {
|
44 |
width: 100%;
|
45 |
height: calc(100% - 40px);
|
46 |
margin-top: 40px;
|
47 |
+
text-align: center;
|
48 |
}
|
49 |
+
|
50 |
+
.img-container img {
|
51 |
+
max-width: 100%;
|
52 |
+
max-height: 100%;
|
53 |
border: 1px solid #ddd;
|
54 |
+
border-radius: 6px;
|
|
|
|
|
|
|
|
|
|
|
|
|
55 |
}
|
56 |
"""
|
57 |
|
58 |
+
modal_html = """
|
59 |
+
<div id="imgModal" class="img-modal">
|
60 |
+
<div class="img-modal-content">
|
61 |
+
<button class="close-btn" onclick="document.getElementById('imgModal').style.display='none'; document.body.style.overflow='auto';">×</button>
|
62 |
+
<div class="img-container">
|
63 |
+
<img src="file=policy_page1.png" alt="Policy Page">
|
|
|
|
|
64 |
</div>
|
65 |
</div>
|
66 |
+
</div>
|
67 |
+
|
68 |
+
<script>
|
69 |
+
document.addEventListener('click', function(e) {
|
70 |
+
const modal = document.getElementById('imgModal');
|
71 |
+
if (modal && e.target === modal) {
|
72 |
+
modal.style.display = 'none';
|
73 |
+
document.body.style.overflow = 'auto';
|
74 |
+
}
|
75 |
+
});
|
76 |
+
|
77 |
+
function showPolicyModal() {
|
78 |
+
const modal = document.getElementById('imgModal');
|
79 |
+
if (modal) {
|
80 |
+
modal.style.display = 'block';
|
81 |
+
document.body.style.overflow = 'hidden';
|
82 |
+
}
|
83 |
+
}
|
84 |
+
</script>
|
85 |
+
"""
|
86 |
|
87 |
with gr.Blocks(css=modal_css) as app:
|
88 |
+
gr.Markdown("## Hate Speech Policy Viewer (Image-based Modal)")
|
89 |
gr.HTML(modal_html)
|
90 |
+
|
91 |
+
open_button = gr.Button("📄 View Policy (Image Popup)")
|
92 |
+
open_button.click(
|
93 |
+
fn=None,
|
94 |
+
inputs=None,
|
95 |
+
outputs=None,
|
96 |
+
_js="showPolicyModal"
|
97 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
98 |
|
99 |
return app
|
100 |
|
101 |
if __name__ == "__main__":
|
102 |
+
app = create_policy_image_modal_app()
|
103 |
app.launch()
|