Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,17 +1,30 @@
|
|
1 |
import gradio as gr
|
2 |
-
|
|
|
3 |
|
4 |
-
#
|
5 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
|
7 |
def respond(message, history):
|
8 |
-
|
9 |
-
|
10 |
-
|
|
|
|
|
|
|
11 |
|
12 |
-
# استفاده از تمپلت آماده Chat Interface
|
13 |
gr.ChatInterface(
|
14 |
respond,
|
15 |
-
title="
|
16 |
-
|
17 |
-
).launch()
|
|
|
1 |
import gradio as gr
|
2 |
+
import torch
|
3 |
+
from transformers import pipeline, logging
|
4 |
|
5 |
+
# کاهش مصرف حافظه
|
6 |
+
logging.set_verbosity_error()
|
7 |
+
torch.backends.cudnn.benchmark = True
|
8 |
+
|
9 |
+
# استفاده از مدل سبکتر
|
10 |
+
model_name = "deepseek-ai/deepseek-coder-1.3b-base"
|
11 |
+
coder = pipeline(
|
12 |
+
"text-generation",
|
13 |
+
model=model_name,
|
14 |
+
device=0 if torch.cuda.is_available() else -1,
|
15 |
+
torch_dtype=torch.float16
|
16 |
+
)
|
17 |
|
18 |
def respond(message, history):
|
19 |
+
try:
|
20 |
+
prompt = f"### سوال: {message}\n### پاسخ:"
|
21 |
+
response = coder(prompt, max_new_tokens=150)[0]['generated_text']
|
22 |
+
return response.split("### پاسخ:")[-1].strip()
|
23 |
+
except Exception as e:
|
24 |
+
return f"خطا: {str(e)}"
|
25 |
|
|
|
26 |
gr.ChatInterface(
|
27 |
respond,
|
28 |
+
title="🧑💻 دستیار برنامهنویسی",
|
29 |
+
description="پرسشهای برنامهنویسی خود را مطرح کنید"
|
30 |
+
).launch(server_port=7860, share=False)
|