Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import AutoModelForSequenceClassification, AutoTokenizer, pipeline
|
| 3 |
+
|
| 4 |
+
# Load model and tokenizer (this one detects Arabic dialects)
|
| 5 |
+
model_name = "badrex/mms-300m-arabic-dialect-identifier"
|
| 6 |
+
model = AutoModelForSequenceClassification.from_pretrained(model_name)
|
| 7 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 8 |
+
clf = pipeline("text-classification", model=model, tokenizer=tokenizer)
|
| 9 |
+
|
| 10 |
+
def detect_dialect(text):
|
| 11 |
+
results = clf(text)
|
| 12 |
+
label = results[0]['label']
|
| 13 |
+
score = round(results[0]['score'], 3)
|
| 14 |
+
return f"Dialect: {label} (confidence {score})"
|
| 15 |
+
|
| 16 |
+
demo = gr.Interface(fn=detect_dialect,
|
| 17 |
+
inputs=gr.Textbox(label="Arabic text"),
|
| 18 |
+
outputs="text",
|
| 19 |
+
title="Arabic Accent Identifier",
|
| 20 |
+
description="Detects Arabic dialects such as Egyptian, Gulf, Levantine, etc.")
|
| 21 |
+
|
| 22 |
+
demo.launch()
|