Spaces:
Runtime error
Runtime error
asas.py
Browse files
app.py
ADDED
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import pipeline
|
3 |
+
|
4 |
+
# تحميل نموذج StarCoder (يمكن استبداله بنموذج آخر عند الحاجة)
|
5 |
+
code_assistant = pipeline("text-generation", model="bigcode/starcoder", trust_remote_code=True)
|
6 |
+
|
7 |
+
def answer_question(prompt):
|
8 |
+
try:
|
9 |
+
response = code_assistant(prompt, max_new_tokens=256, do_sample=True)[0]['generated_text']
|
10 |
+
return response[len(prompt):] # إزالة الجزء المكرر من النص المدخل
|
11 |
+
except Exception as e:
|
12 |
+
return f"حدث خطأ: {str(e)}"
|
13 |
+
|
14 |
+
with gr.Blocks(title="مساعدك البرمجي الذكي") as demo:
|
15 |
+
gr.Markdown("""
|
16 |
+
# 🤖 مساعدك البرمجي الذكي
|
17 |
+
أدخل سؤالك البرمجي (مثل تصحيح كود، شرح، تحويل لغات، إلخ)
|
18 |
+
""")
|
19 |
+
|
20 |
+
with gr.Row():
|
21 |
+
prompt = gr.Textbox(label="اكتب سؤالك هنا:", lines=5, placeholder="مثال: حول هذا الكود من Python إلى C++")
|
22 |
+
|
23 |
+
output = gr.Textbox(label="الإجابة / الكود:", lines=10)
|
24 |
+
|
25 |
+
btn = gr.Button("أجبني ✨")
|
26 |
+
btn.click(fn=answer_question, inputs=prompt, outputs=output)
|
27 |
+
|
28 |
+
if __name__ == "__main__":
|
29 |
+
demo.launch()
|
30 |
+
|