Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -27,8 +27,10 @@ def compute_metrics(ar_text: str) -> Dict[str, float]:
|
|
| 27 |
words = tokenize_words(text_norm)
|
| 28 |
n_sents, n_words = max(len(sents),1), max(len(words),1)
|
| 29 |
diff_count = sum(1 for w in words if difficult_word(w))
|
| 30 |
-
try:
|
| 31 |
-
|
|
|
|
|
|
|
| 32 |
return {
|
| 33 |
"Word count": n_words,
|
| 34 |
"Sentence count": n_sents,
|
|
@@ -48,21 +50,15 @@ def analyze_text(text):
|
|
| 48 |
stats = compute_metrics(text)
|
| 49 |
return {"Predicted_Label": label, **stats}
|
| 50 |
|
| 51 |
-
|
| 52 |
-
# ✅ هذا هو الجزء الجديد اللي يفعّل الـ API فعليًا:
|
| 53 |
demo = gr.Interface(
|
| 54 |
fn=analyze_text,
|
| 55 |
inputs=gr.Textbox(label="أدخل النص العربي هنا", lines=6),
|
| 56 |
outputs=gr.JSON(label="نتائج التحليل"),
|
| 57 |
-
api_name="predict", #
|
| 58 |
title="Arabic Readability Analyzer",
|
| 59 |
description="أداة ذكية لتقييم مقروئية النصوص العربية باستخدام نموذج AraBERT."
|
| 60 |
)
|
| 61 |
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
server_port=7860,
|
| 65 |
-
enable_queue=True,
|
| 66 |
-
share=True,
|
| 67 |
-
allowed_origins=["*"] # ✅ this line enables CORS for your React app
|
| 68 |
-
)
|
|
|
|
| 27 |
words = tokenize_words(text_norm)
|
| 28 |
n_sents, n_words = max(len(sents),1), max(len(words),1)
|
| 29 |
diff_count = sum(1 for w in words if difficult_word(w))
|
| 30 |
+
try:
|
| 31 |
+
osman = float(textstat.osman(ar_text))
|
| 32 |
+
except Exception:
|
| 33 |
+
osman = 0.0
|
| 34 |
return {
|
| 35 |
"Word count": n_words,
|
| 36 |
"Sentence count": n_sents,
|
|
|
|
| 50 |
stats = compute_metrics(text)
|
| 51 |
return {"Predicted_Label": label, **stats}
|
| 52 |
|
| 53 |
+
# ✅ This single interface handles both UI and API:
|
|
|
|
| 54 |
demo = gr.Interface(
|
| 55 |
fn=analyze_text,
|
| 56 |
inputs=gr.Textbox(label="أدخل النص العربي هنا", lines=6),
|
| 57 |
outputs=gr.JSON(label="نتائج التحليل"),
|
| 58 |
+
api_name="predict", # important for your frontend to call /run/predict
|
| 59 |
title="Arabic Readability Analyzer",
|
| 60 |
description="أداة ذكية لتقييم مقروئية النصوص العربية باستخدام نموذج AraBERT."
|
| 61 |
)
|
| 62 |
|
| 63 |
+
# ✅ Launch the Space with CORS enabled
|
| 64 |
+
demo.launch(server_name="0.0.0.0", server_port=7860, allowed_origins=["*"])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|