Spaces:
Running on Zero
Running on Zero
Download app.py from zico2m/comments-analyzer: direct link, hf CLI and curl.
- Browser
- Download file 1.38 kB
-
https://huggingface.co/spaces/zico2m/comments-analyzer/resolve/main/app.py
- Command line
-
hf download hf://spaces/zico2m/comments-analyzer/app.py
-
curl -L -o app.py https://huggingface.co/spaces/zico2m/comments-analyzer/resolve/main/app.py
1.38 kB
| import joblib | |
| import gradio as gr | |
| from huggingface_hub import hf_hub_download | |
| import spaces | |
| repo_id = "zico2m/comments-classifiers" | |
| vectorizer_path = hf_hub_download(repo_id=repo_id, filename="tfidf_vectorizer.pkl") | |
| sentiment_path = hf_hub_download(repo_id=repo_id, filename="sentiment_model.pkl") | |
| vectorizer = joblib.load(vectorizer_path) | |
| sentiment_model = joblib.load(sentiment_path) | |
| def classify_comment(text): | |
| if not text or not text.strip(): | |
| return "الرجاء إدخال نص صالح للتحليل." | |
| text_str = str(text) | |
| transformed_text = vectorizer.transform([text_str]) | |
| prediction = str(sentiment_model.predict(transformed_text)[0]) | |
| # تحويل الرقم إلى نص توضيحي (يمكنك تعديل المسميات حسب مشروعك) | |
| result_text = "سلبي (Negative)" if prediction == "0" else "إيجابي/آخر (Positive)" | |
| return result_text | |
| demo = gr.Interface( | |
| fn=classify_comment, | |
| inputs=gr.Textbox(lines=3, label="اكتب تعليقك هنا بالعربية:"), | |
| outputs=gr.Textbox(label="نتيجة التحليل"), | |
| title="تحليل وتصنيف التعليقات العربية", | |
| description="أدخل أي تعليق وسيقوم النموذج بتحليله وإظهار النتيجة فوراً." | |
| ) | |
| if __name__ == "__main__": | |
| demo.launch() |