Upload app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
| 3 |
+
import torch
|
| 4 |
+
|
| 5 |
+
# Load model
|
| 6 |
+
model_path = "yazied49/disabilityy_model_final"
|
| 7 |
+
tokenizer = AutoTokenizer.from_pretrained(model_path)
|
| 8 |
+
model = AutoModelForSequenceClassification.from_pretrained(model_path)
|
| 9 |
+
|
| 10 |
+
# Prediction function
|
| 11 |
+
def predict(text):
|
| 12 |
+
inputs = tokenizer(text, return_tensors="pt", truncation=True, padding=True)
|
| 13 |
+
with torch.no_grad():
|
| 14 |
+
outputs = model(**inputs)
|
| 15 |
+
probs = torch.nn.functional.softmax(outputs.logits, dim=1)
|
| 16 |
+
pred_id = torch.argmax(probs, dim=1).item()
|
| 17 |
+
confidence = torch.max(probs).item()
|
| 18 |
+
label = model.config.id2label[str(pred_id)] # تأكد إن id2label keys = strings
|
| 19 |
+
|
| 20 |
+
return f"{label} ({round(confidence * 100, 2)}%)"
|
| 21 |
+
|
| 22 |
+
# Create Gradio interface
|
| 23 |
+
demo = gr.Interface(fn=predict, inputs="text", outputs="text", title="Disability Classifier")
|
| 24 |
+
|
| 25 |
+
# Launch app
|
| 26 |
+
demo.launch()
|