import gradio as gr from transformers import pipeline import torch # تهيئة النموذج (اختر النموذج المناسب لمهمتك) classifier = pipeline("text-classification", model="distilbert-base-uncased-finetuned-sst-2-english") # دالة للتنبؤ def predict(text): try: result = classifier(text)[0] return { "label": result['label'], "score": round(result['score'], 4) } except Exception as e: return {"error": str(e)} # إنشاء واجهة Gradio demo = gr.Interface( fn=predict, inputs=gr.Textbox(lines=2, placeholder="أدخل النص هنا...", label="النص"), outputs=gr.JSON(label="النتيجة"), title="تصنيف النص باستخدام Hugging Face", description="أدخل نصًا لتصنيف المشاعر (إيجابي/سلبي)", examples=[ ["I love this movie, it's amazing!"], ["This is the worst product I've ever bought."], ["The weather is nice today."] ] ) if __name__ == "__main__": demo.launch(share=True) # share=True لإنشاء رابط عام