Upload folder using huggingface_hub
Browse files
test.py
CHANGED
@@ -1,8 +1,10 @@
|
|
1 |
import gradio as gr
|
2 |
|
3 |
-
def
|
|
|
|
|
4 |
modal_css = """
|
5 |
-
.
|
6 |
display: none;
|
7 |
position: fixed;
|
8 |
z-index: 1000;
|
@@ -12,20 +14,18 @@ def create_policy_image_modal_app():
|
|
12 |
height: 100%;
|
13 |
background-color: rgba(0,0,0,0.7);
|
14 |
overflow: auto;
|
|
|
|
|
15 |
}
|
16 |
-
|
17 |
-
.img-modal-content {
|
18 |
background-color: white;
|
19 |
margin: 2% auto;
|
20 |
padding: 20px;
|
21 |
width: 90%;
|
22 |
max-width: 900px;
|
23 |
-
height: 90%;
|
24 |
-
box-shadow: 0 5px 15px rgba(0,0,0,0.3);
|
25 |
border-radius: 8px;
|
26 |
position: relative;
|
27 |
}
|
28 |
-
|
29 |
.close-btn {
|
30 |
position: absolute;
|
31 |
right: 15px;
|
@@ -37,64 +37,51 @@ def create_policy_image_modal_app():
|
|
37 |
border: none;
|
38 |
border-radius: 4px;
|
39 |
padding: 5px 15px;
|
40 |
-
z-index: 1001;
|
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 |
-
.open-policy-btn {
|
58 |
-
background-color: #FCA539;
|
59 |
-
color: #000;
|
60 |
-
font-weight: bold;
|
61 |
-
padding: 10px 20px;
|
62 |
-
border: none;
|
63 |
-
border-radius: 6px;
|
64 |
-
font-size: 16px;
|
65 |
-
cursor: pointer;
|
66 |
}
|
67 |
"""
|
68 |
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
|
|
|
|
76 |
</div>
|
77 |
</div>
|
78 |
-
|
79 |
-
<button class="open-policy-btn" onclick="document.getElementById('imgModal').style.display='block'; document.body.style.overflow='hidden';">📄 View Hate Speech Policy</button>
|
80 |
-
|
81 |
-
<script>
|
82 |
-
document.addEventListener('click', function(e) {
|
83 |
-
const modal = document.getElementById('imgModal');
|
84 |
-
if (modal && e.target === modal) {
|
85 |
-
modal.style.display = 'none';
|
86 |
-
document.body.style.overflow = 'auto';
|
87 |
-
}
|
88 |
-
});
|
89 |
-
</script>
|
90 |
"""
|
91 |
|
92 |
with gr.Blocks(css=modal_css) as app:
|
93 |
-
gr.Markdown("# Policy Viewer Demo")
|
94 |
gr.HTML(modal_html)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
95 |
|
96 |
return app
|
97 |
|
98 |
if __name__ == "__main__":
|
99 |
-
app =
|
100 |
app.launch()
|
|
|
1 |
import gradio as gr
|
2 |
|
3 |
+
def create_policy_modal_app():
|
4 |
+
image_paths = [f"policy_page{i+1}.png" for i in range(5)] # Adjust page count!
|
5 |
+
|
6 |
modal_css = """
|
7 |
+
.policy-modal {
|
8 |
display: none;
|
9 |
position: fixed;
|
10 |
z-index: 1000;
|
|
|
14 |
height: 100%;
|
15 |
background-color: rgba(0,0,0,0.7);
|
16 |
overflow: auto;
|
17 |
+
justify-content: center;
|
18 |
+
align-items: center;
|
19 |
}
|
20 |
+
.policy-modal-content {
|
|
|
21 |
background-color: white;
|
22 |
margin: 2% auto;
|
23 |
padding: 20px;
|
24 |
width: 90%;
|
25 |
max-width: 900px;
|
|
|
|
|
26 |
border-radius: 8px;
|
27 |
position: relative;
|
28 |
}
|
|
|
29 |
.close-btn {
|
30 |
position: absolute;
|
31 |
right: 15px;
|
|
|
37 |
border: none;
|
38 |
border-radius: 4px;
|
39 |
padding: 5px 15px;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
40 |
}
|
41 |
"""
|
42 |
|
43 |
+
images_html = "".join(
|
44 |
+
f"<img src='file={path}' style='width:100%; margin-bottom:20px;' />" for path in image_paths
|
45 |
+
)
|
46 |
+
|
47 |
+
modal_html = f"""
|
48 |
+
<div id="policyModal" class="policy-modal">
|
49 |
+
<div class="policy-modal-content">
|
50 |
+
<button class="close-btn" onclick="document.getElementById('policyModal').style.display='none';">×</button>
|
51 |
+
{images_html}
|
52 |
</div>
|
53 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
54 |
"""
|
55 |
|
56 |
with gr.Blocks(css=modal_css) as app:
|
|
|
57 |
gr.HTML(modal_html)
|
58 |
+
button = gr.Button("View Hate Speech Policy")
|
59 |
+
|
60 |
+
button.click(fn=None, inputs=None, outputs=None, _js="""
|
61 |
+
function() {
|
62 |
+
const modal = document.getElementById('policyModal');
|
63 |
+
if (modal) {
|
64 |
+
modal.style.display = 'flex';
|
65 |
+
document.body.style.overflow = 'hidden';
|
66 |
+
}
|
67 |
+
return [];
|
68 |
+
}
|
69 |
+
""")
|
70 |
+
|
71 |
+
gr.HTML("""
|
72 |
+
<script>
|
73 |
+
document.addEventListener('click', function(e) {
|
74 |
+
const modal = document.getElementById('policyModal');
|
75 |
+
if (modal && e.target === modal) {
|
76 |
+
modal.style.display = 'none';
|
77 |
+
document.body.style.overflow = 'auto';
|
78 |
+
}
|
79 |
+
});
|
80 |
+
</script>
|
81 |
+
""")
|
82 |
|
83 |
return app
|
84 |
|
85 |
if __name__ == "__main__":
|
86 |
+
app = create_policy_modal_app()
|
87 |
app.launch()
|