Madar / app.py
NvbilVmir1's picture
Update app.py
19347b0 verified
import gradio as gr
from transformers import AutoTokenizer, AutoModelForSequenceClassification
import torch
# ู…ูˆุฏูŠู„ BRET
model_name = "NvbilVmir1/Madar"
# ุชุญู…ูŠู„ ุงู„ู…ูˆุฏูŠู„ ูˆุงู„ุชูˆูƒู†ูŠุฒุฑ
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForSequenceClassification.from_pretrained(model_name)
id2label = model.config.id2label
def predict_dialect(text):
inputs = tokenizer(text, return_tensors="pt", truncation=True, padding=True)
with torch.no_grad():
outputs = model(**inputs)
pred = torch.argmax(outputs.logits, dim=-1).item()
return id2label[pred]
title = "AraELECTRA Arabic Dialect Classifier ๐ŸŒ"
description = """
Detect the Arabic dialect from the input text.
Dialects include: African, Khaleeji, Levant, and Egyptian.
"""
interface = gr.Interface(
fn=predict_dialect,
inputs=gr.Textbox(lines=3, placeholder="Type an Arabic sentence here..."),
outputs="text",
title=title,
description=description,
theme="default",
allow_flagging="never",
)
if __name__ == "__main__":
interface.launch()