Menna / app.py
MennatullahHany's picture
Update app.py
5cd0946 verified
raw
history blame contribute delete
975 Bytes
import gradio as gr
from transformers import pipeline
# ุชุญู…ูŠู„ ุงู„ู…ูˆุฏูŠู„
classifier = pipeline(
"text-classification",
model="MennatullahHany/Arabic-Speech-Guard",
tokenizer="MennatullahHany/Arabic-Speech-Guard",
return_all_scores=True
)
# mapping labels
label_map = {
"LABEL_0": "SAFE โœ…",
"LABEL_1": "DANGER โš ๏ธ"
}
def predict(text):
if text.strip() == "":
return "โŒ Please enter Arabic text"
results = classifier(text)[0] # ู‚ุงุฆู…ุฉ ู…ู† ุงู„ู‚ูŠู… ู„ูƒู„ label
output = ""
for r in results:
mapped_label = label_map.get(r['label'], r['label'])
output += f"{mapped_label}: {round(r['score']*100, 2)}%\n"
return output
# ูˆุงุฌู‡ุฉ Gradio
demo = gr.Interface(
fn=predict,
inputs=gr.Textbox(lines=4, placeholder="ุงูƒุชุจ ุงู„ู†ุต ู‡ู†ุง..."),
outputs="text",
title="Arabic Speech Guard ๐Ÿ›ก๏ธ",
description="Detect offensive Arabic content"
)
demo.launch()