import gradio as gr from transformers import pipeline # تحميل نموذج التصحيح الموثوق من CAMeL-Lab CORRECTOR_MODEL_ID = "CAMeL-Lab/arabart-qalb15-gec-ged-13" try: # هذا النموذج يستخدم "text2text-generation" corrector_pipe = pipeline("text2text-generation", model=CORRECTOR_MODEL_ID) print("Text correction pipeline loaded successfully!") except Exception as e: print(f"Error loading pipeline: {e}") corrector_pipe = None # دالة لتصحيح النص def correct_text(text_input): if corrector_pipe is None: return "Error: Model pipeline could not be loaded." if not text_input or not text_input.strip(): return "Please provide text to correct." try: # نقوم بتمرير النص مباشرة إلى النموذج corrected_result = corrector_pipe(text_input, max_length=1024) corrected_text = corrected_result[0]['generated_text'] return corrected_text except Exception as e: return f"An error occurred: {str(e)}" # الواجهة تستقبل نصًا كمُدخل وتُخرج نصًا مصححًا gr.Interface( fn=correct_text, inputs=gr.Textbox(lines=5, label="النص الأصلي"), outputs=gr.Textbox(label="النص المصحح"), title="Arabic Text Correction (Service B)", description="This service corrects Arabic text using the AraBART GEC model." ).launch(debug=True)