Update app.py
Browse files
app.py
CHANGED
@@ -30,41 +30,61 @@ def analyze(text):
|
|
30 |
return hate_label, f"{hate_conf:.2f}", dial_label, f"{dial_conf:.2f}", f"{score:.2f}", action
|
31 |
|
32 |
|
33 |
-
with
|
34 |
-
|
35 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
36 |
with gr.Column(scale=1):
|
37 |
-
gr.
|
38 |
-
|
|
|
|
|
39 |
|
40 |
-
|
41 |
-
|
42 |
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
|
|
54 |
|
55 |
-
# Main app
|
56 |
with gr.Column(scale=3):
|
57 |
gr.Markdown("### Enter Arabic Text for Analysis")
|
|
|
58 |
input_text = gr.Textbox(lines=4, placeholder="اكتب هنا...", label="Arabic Text")
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
30 |
return hate_label, f"{hate_conf:.2f}", dial_label, f"{dial_conf:.2f}", f"{score:.2f}", action
|
31 |
|
32 |
|
33 |
+
# ---------- UI (Blocks with Sidebar) ----------
|
34 |
+
SIDEBAR_CSS = """
|
35 |
+
#sidebar-panel {
|
36 |
+
background: #2b2b2b; /* darker grey than main area (good for dark theme) */
|
37 |
+
border: 1px solid rgba(255,255,255,0.08);
|
38 |
+
border-radius: 10px;
|
39 |
+
padding: 18px;
|
40 |
+
}
|
41 |
+
"""
|
42 |
+
|
43 |
+
with gr.Blocks(css=SIDEBAR_CSS, theme="default") as demo:
|
44 |
+
with gr.Row(equal_height=True):
|
45 |
+
# Sidebar (left)
|
46 |
with gr.Column(scale=1):
|
47 |
+
with gr.Group(elem_id="sidebar-panel"):
|
48 |
+
gr.Markdown(
|
49 |
+
"""
|
50 |
+
## 🛡️ Arabic Content Safety Analyzer
|
51 |
|
52 |
+
**Purpose**
|
53 |
+
Analyze Arabic text for harmful or threatening language.
|
54 |
|
55 |
+
**Features**
|
56 |
+
- **Hate Speech Classification** (Offensive, Racism, Sexism, Religious Discrimination)
|
57 |
+
- **Dialect Detection** (Gulf, Levant, Egyptian, MSA)
|
58 |
+
- **Threat Severity Score** (0–1 based on label + confidence)
|
59 |
+
- **Recommended Action** (rule-based suggestion)
|
60 |
|
61 |
+
**How to Use**
|
62 |
+
1. Enter Arabic text in the box.
|
63 |
+
2. Click **Analyze**.
|
64 |
+
3. Review the results and suggested action.
|
65 |
+
"""
|
66 |
+
)
|
67 |
|
68 |
+
# Main app (right)
|
69 |
with gr.Column(scale=3):
|
70 |
gr.Markdown("### Enter Arabic Text for Analysis")
|
71 |
+
|
72 |
input_text = gr.Textbox(lines=4, placeholder="اكتب هنا...", label="Arabic Text")
|
73 |
+
|
74 |
+
out_hate = gr.Textbox(label="Hate Speech Label", interactive=False)
|
75 |
+
out_hate_conf = gr.Textbox(label="Label Confidence", interactive=False)
|
76 |
+
out_dialect = gr.Textbox(label="Dialect", interactive=False)
|
77 |
+
out_dialect_conf = gr.Textbox(label="Dialect Confidence", interactive=False)
|
78 |
+
out_score = gr.Textbox(label="Threat Score", interactive=False)
|
79 |
+
out_action = gr.Textbox(label="Recommended Action", interactive=False)
|
80 |
+
|
81 |
+
analyze_btn = gr.Button("Analyze", variant="primary")
|
82 |
+
analyze_btn.click(
|
83 |
+
fn=analyze,
|
84 |
+
inputs=input_text,
|
85 |
+
outputs=[out_hate, out_hate_conf, out_dialect, out_dialect_conf, out_score, out_action],
|
86 |
+
)
|
87 |
+
|
88 |
+
# ---------- Launch ----------
|
89 |
+
if __name__ == "__main__":
|
90 |
+
demo.launch()
|