GhadaAlothman commited on
Commit
92e4e70
·
verified ·
1 Parent(s): e30f18d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -10
app.py CHANGED
@@ -15,11 +15,20 @@ AR_LETTERS = r"[\u0600-\u06FF]"
15
  SENT_SEP = re.compile(r"[\.!\?؟؛…]+")
16
  WORD_RE = re.compile(fr"{AR_LETTERS}+")
17
 
18
- def strip_diacritics(s: str): return DIACRITICS.sub("", s)
19
- def normalize_arabic(s: str): return re.sub("[\u0622\u0623\u0625]", "ا", strip_diacritics(s)).replace("ى","ي").replace("ة","ه")
20
- def split_sentences(text: str): return [p.strip() for p in SENT_SEP.split(text) if p.strip()]
21
- def tokenize_words(text: str): return WORD_RE.findall(text)
22
- def difficult_word(w: str, min_len: int = 6): return len(w) >= min_len
 
 
 
 
 
 
 
 
 
23
 
24
  def compute_metrics(ar_text: str) -> Dict[str, float]:
25
  text_norm = normalize_arabic(ar_text)
@@ -50,16 +59,19 @@ def analyze_text(text):
50
  stats = compute_metrics(text)
51
  return {"Predicted_Label": label, **stats}
52
 
53
- # ✅ الواجهة الأساسية + تعريف الـ API endpoint بشكل صريح
 
 
 
 
54
  demo = gr.Interface(
55
  fn=analyze_text,
56
  inputs=gr.Textbox(label="أدخل النص العربي هنا", lines=6),
57
  outputs=gr.JSON(label="نتائج التحليل"),
58
- api_name="predict", # هذا السطر ينشئ endpoint /run/predict فعليًا
59
  title="Arabic Readability Analyzer",
60
  description="أداة ذكية لتقييم مقروئية النصوص العربية باستخدام نموذج AraBERT."
61
  )
62
 
63
- if __name__ == "__main__":
64
- demo.queue()
65
- demo.launch(server_name="0.0.0.0", server_port=7860)
 
15
  SENT_SEP = re.compile(r"[\.!\?؟؛…]+")
16
  WORD_RE = re.compile(fr"{AR_LETTERS}+")
17
 
18
+ def strip_diacritics(s: str):
19
+ return DIACRITICS.sub("", s)
20
+
21
+ def normalize_arabic(s: str):
22
+ return re.sub("[\u0622\u0623\u0625]", "ا", strip_diacritics(s)).replace("ى","ي").replace("ة","ه")
23
+
24
+ def split_sentences(text: str):
25
+ return [p.strip() for p in SENT_SEP.split(text) if p.strip()]
26
+
27
+ def tokenize_words(text: str):
28
+ return WORD_RE.findall(text)
29
+
30
+ def difficult_word(w: str, min_len: int = 6):
31
+ return len(w) >= min_len
32
 
33
  def compute_metrics(ar_text: str) -> Dict[str, float]:
34
  text_norm = normalize_arabic(ar_text)
 
59
  stats = compute_metrics(text)
60
  return {"Predicted_Label": label, **stats}
61
 
62
+
63
+ # ✅ السماح بطلبات من أي origin (Vercel أو غيره)
64
+ gr.set_static_paths(allowed_origins=["*"])
65
+
66
+ # ✅ واجهة Gradio + تفعيل API endpoint
67
  demo = gr.Interface(
68
  fn=analyze_text,
69
  inputs=gr.Textbox(label="أدخل النص العربي هنا", lines=6),
70
  outputs=gr.JSON(label="نتائج التحليل"),
71
+ api_name="predict",
72
  title="Arabic Readability Analyzer",
73
  description="أداة ذكية لتقييم مقروئية النصوص العربية باستخدام نموذج AraBERT."
74
  )
75
 
76
+ # ✅ إطلاق التطبيق
77
+ demo.launch(server_name="0.0.0.0", server_port=7860, share=True)