File size: 1,959 Bytes
295e82f
f817322
 
295e82f
f817322
 
 
 
 
6e65f59
f817322
 
 
 
 
 
 
295e82f
f817322
b971ae2
 
f817322
 
b971ae2
f817322
 
 
 
 
 
 
 
 
 
 
295e82f
b971ae2
f817322
b971ae2
f817322
b971ae2
 
f817322
 
b971ae2
6e65f59
b971ae2
 
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import gradio as gr
from huggingface_hub import hf_hub_download
from llama_cpp import Llama

print("GGUF मॉडल डाउनलोड हो रहा है (पहली बार में 1-2 मिनट लगेंगे)...")
model_path = hf_hub_download(
    repo_id="Qwen/Qwen2.5-3B-Instruct-GGUF",
    filename="qwen2.5-3b-instruct-q4_k_m.gguf"
)

print("मॉडल लोड हो रहा है...")
# n_threads=2 क्योंकि आपके फ्री सर्वर में 2 CPU कोर होते हैं
llm = Llama(
    model_path=model_path,
    n_ctx=2048,  # डेटा माइनिंग के लिए पर्याप्त कॉन्टेक्स्ट मेमोरी
    n_threads=2,
    verbose=False
)
print("3B मॉडल सफलतापूर्वक लोड हो गया!")

def generate_response(message, history):
    # Qwen का एकदम सही प्रॉम्प्ट फॉर्मेट
    formatted_prompt = "<|im_start|>system\nYou are a logical data mining assistant.<|im_end|>\n"
    
    for user_msg, bot_msg in history:
        formatted_prompt += f"<|im_start|>user\n{user_msg}<|im_end|>\n<|im_start|>assistant\n{bot_msg}<|im_end|>\n"
        
    formatted_prompt += f"<|im_start|>user\n{message}<|im_end|>\n<|im_start|>assistant\n"

    # मॉडल से जवाब जनरेट करना
    output = llm(
        formatted_prompt,
        max_tokens=250, # जवाब की लंबाई
        temperature=0.3, # लॉजिकल जवाब के लिए कम टेम्परेचर
        stop=["<|im_end|>"]
    )
    
    return output["choices"][0]["text"].strip()

# UI और API सेटअप
demo = gr.ChatInterface(
    fn=generate_response,
    title="🧠 Qwen 3B GGUF Server",
    description="3B Intelligence on a free CPU"
)

if __name__ == "__main__":
    demo.launch(show_error=True)