aieeshashafique commited on
Commit
83f34c3
·
verified ·
1 Parent(s): 7e0e380

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -10
app.py CHANGED
@@ -9,7 +9,7 @@ from transformers import (
9
 
10
  # === Config ===
11
  MODEL_ID = "Omartificial-Intelligence-Space/SA-BERT-Classifier"
12
- HF_TOKEN = os.getenv("HUGGINGFACE_HUB_TOKEN") # Get from Secrets
13
  DEVICE = 0 if torch.cuda.is_available() else -1
14
 
15
  # === Load model and tokenizer ===
@@ -23,21 +23,17 @@ pipeline = TextClassificationPipeline(
23
  model=model,
24
  tokenizer=tokenizer,
25
  device=DEVICE,
26
- return_all_scores=True
27
  )
28
 
29
- # === Prediction function ===
30
  def classify_dialect(text):
31
  results = pipeline(text)[0]
32
  scores = {int(item["label"].split("_")[-1]): item["score"] for item in results}
33
  p_non_saudi = scores.get(0, 0.0)
34
  p_saudi = scores.get(1, 0.0)
35
  prediction = "Saudi Dialect" if p_saudi > p_non_saudi else "Non-Saudi Dialect"
36
- return {
37
- "Saudi Dialect (Probability)": round(p_saudi, 4),
38
- "Non-Saudi Dialect (Probability)": round(p_non_saudi, 4),
39
- "Final Prediction": prediction
40
- }
41
 
42
  # === Gradio Interface ===
43
  demo = gr.Interface(
@@ -48,8 +44,9 @@ demo = gr.Interface(
48
  gr.Label(label="Non-Saudi Dialect (Probability)"),
49
  gr.Textbox(label="Final Prediction")
50
  ],
51
- title="Saudi Dialect Classifier",
52
- description="نموذج لتصنيف الجملة هل هي باللهجة السعودية أم لا باستخدام BERT"
 
53
  )
54
 
55
  # === Launch App ===
 
9
 
10
  # === Config ===
11
  MODEL_ID = "Omartificial-Intelligence-Space/SA-BERT-Classifier"
12
+ HF_TOKEN = os.getenv("HUGGINGFACE_HUB_TOKEN")
13
  DEVICE = 0 if torch.cuda.is_available() else -1
14
 
15
  # === Load model and tokenizer ===
 
23
  model=model,
24
  tokenizer=tokenizer,
25
  device=DEVICE,
26
+ top_k=None # replaces deprecated return_all_scores
27
  )
28
 
29
+ # === Inference function ===
30
  def classify_dialect(text):
31
  results = pipeline(text)[0]
32
  scores = {int(item["label"].split("_")[-1]): item["score"] for item in results}
33
  p_non_saudi = scores.get(0, 0.0)
34
  p_saudi = scores.get(1, 0.0)
35
  prediction = "Saudi Dialect" if p_saudi > p_non_saudi else "Non-Saudi Dialect"
36
+ return round(p_saudi, 4), round(p_non_saudi, 4), prediction
 
 
 
 
37
 
38
  # === Gradio Interface ===
39
  demo = gr.Interface(
 
44
  gr.Label(label="Non-Saudi Dialect (Probability)"),
45
  gr.Textbox(label="Final Prediction")
46
  ],
47
+ title="🗣️ Saudi Dialect Classifier",
48
+ description="🔍 نموذج BERT لتصنيف الجمل إلى لهجة سعودية أو غير سعودية.\n\n👩‍💻 Deployed by **Ayesha Shafique**\n\n🌐 Model credit: [Omartificial-Intelligence-Space](https://huggingface.co/Omartificial-Intelligence-Space)",
49
+ allow_flagging="never"
50
  )
51
 
52
  # === Launch App ===