wasmdashai commited on
Commit
b765d86
·
verified ·
1 Parent(s): 6ea3a2b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -16
app.py CHANGED
@@ -1,22 +1,34 @@
1
  from transformers import pipeline
2
  import gradio as gr
 
3
 
4
- # تحميل النموذج
5
- pipe = pipeline("text-generation", model="wasmdashai/Seed-Coder-8B-Instruct-V1")
6
 
7
- # دالة توليد الردود
8
- def chat_with_model(user_input):
9
- messages = [
10
- {"role": "user", "content": user_input},
11
- ]
 
 
 
 
 
 
 
12
  output = pipe(messages, max_new_tokens=200, do_sample=True)
13
- return output[0]['generated_text']
 
 
 
 
 
 
 
 
 
 
 
 
14
 
15
- # واجهة Gradio
16
- gr.Interface(
17
- fn=chat_with_model,
18
- inputs=gr.Textbox(lines=2, placeholder="اكتب سؤالك هنا..."),
19
- outputs="text",
20
- title="Seed-Coder Chat",
21
- description="نموذج Seed-Coder للإجابة على الأسئلة باستخدام نموذج توليد النصوص"
22
- ).launch(share=True)
 
1
  from transformers import pipeline
2
  import gradio as gr
3
+ import torch
4
 
 
 
5
 
6
+ # تحميل النموذج باستخدام GPU إذا متوفر
7
+ pipe = pipeline(
8
+ "text-generation",
9
+ model="wasmdashai/Seed-Coder-8B-Instruct-V1"
10
+
11
+ ).cuda()
12
+
13
+ # دالة الرد
14
+ def respond(message, chat_history):
15
+ messages = [{"role": "user", "content": m[0]} for m in chat_history]
16
+ messages.append({"role": "user", "content": message})
17
+
18
  output = pipe(messages, max_new_tokens=200, do_sample=True)
19
+ reply = output[0]['generated_text']
20
+ return reply
21
+
22
+ # واجهة دردشة Gradio
23
+ chat = gr.ChatInterface(
24
+ fn=respond,
25
+ title="Seed-Coder Chatbot",
26
+ description="دردشة مع نموذج Seed-Coder-8B-Instruct باستخدام GPU",
27
+ chatbot=gr.Chatbot(height=400),
28
+ textbox=gr.Textbox(placeholder="اكتب رسالتك هنا...", container=False, scale=7),
29
+ retry_btn="🔁 إعادة",
30
+ clear_btn="🗑️ مسح",
31
+ )
32
 
33
+ # تشغيل التطبيق
34
+ chat.launch()