Spaces:
Runtime error
Runtime error
| import gradio as gr | |
| from models.space_a import summarize_question | |
| from models.space_b import generate_mentalqa_answer | |
| from models.space_er import extract_entities | |
| # CSS styling for RTL layout | |
| css = """ | |
| body { | |
| direction: rtl; | |
| text-align: right; | |
| } | |
| .container-box { | |
| padding-top: 20px !important; | |
| margin-top: 0 !important; | |
| text-align: right; | |
| } | |
| .output-box { | |
| text-align: right; | |
| direction: rtl; | |
| } | |
| """ | |
| # Task handler | |
| def analyze_text(text, task, classification_type): | |
| if not text.strip(): | |
| return "الرجاء إدخال نص للتحليل." | |
| try: | |
| if task == "classification": | |
| return generate_mentalqa_answer(text) | |
| elif task == "summarization": | |
| return summarize_question(text) | |
| elif task == "entity_recognition": | |
| return extract_entities(text) | |
| else: | |
| return "❌ المهمة غير مدعومة حالياً." | |
| except Exception as e: | |
| return f"❌ حدث خطأ أثناء المعالجة: {str(e)}" | |
| # Dynamic UI visibility for classification type dropdown | |
| def update_ui(task): | |
| return gr.update(visible=(task == "classification")) | |
| # Gradio interface | |
| with gr.Blocks(css=css, title="منصة الصحة النفسية") as demo: | |
| with gr.Column(elem_classes=["container-box"]): | |
| gr.Markdown("## 🧠 تجربة منصة الصحة النفسية") | |
| task_selector = gr.Dropdown( | |
| choices=[ | |
| ("تصنيف الأسئلة والأجوبة", "classification"), | |
| ("تلخيص النصوص", "summarization"), | |
| ("التعرف على الكيانات", "entity_recognition") | |
| ], | |
| label="اختيار نوع المهمة", | |
| value="classification" | |
| ) | |
| user_input = gr.Textbox( | |
| placeholder="أدخل النص هنا لتحليله...", | |
| lines=4, | |
| show_label=False | |
| ) | |
| classification_dropdown = gr.Dropdown( | |
| choices=["تصنيف سؤال", "تصنيف إجابة"], | |
| label="نوع التصنيف", | |
| visible=True | |
| ) | |
| submit_btn = gr.Button("ابدأ التحليل") | |
| output = gr.Textbox( | |
| label="النتيجة", | |
| elem_classes=["output-box"] | |
| ) | |
| # Events | |
| task_selector.change(fn=update_ui, inputs=task_selector, outputs=classification_dropdown) | |
| submit_btn.click(fn=analyze_text, inputs=[user_input, task_selector, classification_dropdown], outputs=output) | |
| if __name__ == "__main__": | |
| demo.launch() | |