Spaces:
Sleeping
Sleeping
requirements.txt
Browse filesgradio
transformers
torch
sentencepiece
app.py
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
|
| 4 |
+
classifier = pipeline(
|
| 5 |
+
"text-classification",
|
| 6 |
+
model="MennatullahHany/Arabic-Speech-Guard",
|
| 7 |
+
tokenizer="MennatullahHany/Arabic-Speech-Guard",
|
| 8 |
+
return_all_scores=True
|
| 9 |
+
)
|
| 10 |
+
|
| 11 |
+
def predict(text):
|
| 12 |
+
if text.strip() == "":
|
| 13 |
+
return "❌ Please enter Arabic text"
|
| 14 |
+
|
| 15 |
+
results = classifier(text)[0]
|
| 16 |
+
output = ""
|
| 17 |
+
for r in results:
|
| 18 |
+
output += f"{r['label']}: {round(r['score']*100, 2)}%\n"
|
| 19 |
+
return output
|
| 20 |
+
|
| 21 |
+
demo = gr.Interface(
|
| 22 |
+
fn=predict,
|
| 23 |
+
inputs=gr.Textbox(lines=4, placeholder="اكتب النص هنا..."),
|
| 24 |
+
outputs="text",
|
| 25 |
+
title="Arabic Speech Guard 🛡️",
|
| 26 |
+
description="Detect offensive Arabic content"
|
| 27 |
+
)
|
| 28 |
+
|
| 29 |
+
demo.launch()
|