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) @spaces.GPU 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()