import gradio as gr from transformers import pipeline # تحميل نموذج StarCoder (يمكن استبداله بنموذج آخر عند الحاجة) code_assistant = pipeline("text-generation", model="bigcode/starcoder", trust_remote_code=True) def answer_question(prompt): try: response = code_assistant(prompt, max_new_tokens=256, do_sample=True)[0]['generated_text'] return response[len(prompt):] # إزالة الجزء المكرر من النص المدخل except Exception as e: return f"حدث خطأ: {str(e)}" with gr.Blocks(title="مساعدك البرمجي الذكي") as demo: gr.Markdown(""" # 🤖 مساعدك البرمجي الذكي أدخل سؤالك البرمجي (مثل تصحيح كود، شرح، تحويل لغات، إلخ) """) with gr.Row(): prompt = gr.Textbox(label="اكتب سؤالك هنا:", lines=5, placeholder="مثال: حول هذا الكود من Python إلى C++") output = gr.Textbox(label="الإجابة / الكود:", lines=10) btn = gr.Button("أجبني ✨") btn.click(fn=answer_question, inputs=prompt, outputs=output) if __name__ == "__main__": demo.launch()