Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
|
| 4 |
+
# Load model from Hugging Face
|
| 5 |
+
classifier = pipeline(
|
| 6 |
+
"text-classification",
|
| 7 |
+
model="MennatullahHany/Arabic-Speech-Guard",
|
| 8 |
+
tokenizer="MennatullahHany/Arabic-Speech-Guard",
|
| 9 |
+
return_all_scores=True
|
| 10 |
+
)
|
| 11 |
+
|
| 12 |
+
def predict(text):
|
| 13 |
+
if text.strip() == "":
|
| 14 |
+
return "❌ Please enter Arabic text"
|
| 15 |
+
|
| 16 |
+
outputs = classifier(text)[0]
|
| 17 |
+
|
| 18 |
+
result = {item["label"]: round(item["score"], 3) for item in outputs}
|
| 19 |
+
return result
|
| 20 |
+
|
| 21 |
+
interface = gr.Interface(
|
| 22 |
+
fn=predict,
|
| 23 |
+
inputs=gr.Textbox(lines=4, placeholder="اكتب نص عربي هنا..."),
|
| 24 |
+
outputs=gr.JSON(label="Prediction"),
|
| 25 |
+
title="🛡️ Arabic Speech Guard",
|
| 26 |
+
description="Arabic offensive & harmful speech detection model"
|
| 27 |
+
)
|
| 28 |
+
|
| 29 |
+
interface.launch()
|