File size: 940 Bytes
e4d14e4
3100b28
 
e4d14e4
3100b28
 
 
 
 
 
 
 
 
 
 
 
e4d14e4
fe6b6c1
3100b28
 
 
 
 
 
e4d14e4
fe6b6c1
e4d14e4
3100b28
 
 
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
import gradio as gr
import torch
from transformers import pipeline, logging

# کاهش مصرف حافظه
logging.set_verbosity_error()
torch.backends.cudnn.benchmark = True

# استفاده از مدل سبک‌تر
model_name = "deepseek-ai/deepseek-coder-1.3b-base"
coder = pipeline(
    "text-generation",
    model=model_name,
    device=0 if torch.cuda.is_available() else -1,
    torch_dtype=torch.float16
)

def respond(message, history):
    try:
        prompt = f"### سوال: {message}\n### پاسخ:"
        response = coder(prompt, max_new_tokens=150)[0]['generated_text']
        return response.split("### پاسخ:")[-1].strip()
    except Exception as e:
        return f"خطا: {str(e)}"

gr.ChatInterface(
    respond,
    title="🧑‍💻 دستیار برنامه‌نویسی",
    description="پرسش‌های برنامه‌نویسی خود را مطرح کنید"
).launch(server_port=7860, share=False)