Spaces:
Runtime error
Runtime error
File size: 1,220 Bytes
9bbcb69 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
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()
|