Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from llama_cpp import Llama
|
| 3 |
+
from huggingface_hub import hf_hub_download
|
| 4 |
+
|
| 5 |
+
# 1. मॉडल डाउनलोड करना (डायरेक्ट सर्वर पर)
|
| 6 |
+
# हमें 5GB का DeepSeek-R1-Distill मॉडल चाहिए
|
| 7 |
+
print("⏳ मॉडल डाउनलोड हो रहा है... (इसमें 1-2 मिनट लगेंगे)")
|
| 8 |
+
model_path = hf_hub_download(
|
| 9 |
+
repo_id="unsloth/DeepSeek-R1-Distill-Llama-8B-GGUF",
|
| 10 |
+
filename="DeepSeek-R1-Distill-Llama-8B-Q4_K_M.gguf"
|
| 11 |
+
)
|
| 12 |
+
print("✅ मॉडल डाउनलोड हो गया!")
|
| 13 |
+
|
| 14 |
+
# 2. दिमाग लोड करना (16GB RAM का फायदा)
|
| 15 |
+
llm = Llama(
|
| 16 |
+
model_path=model_path,
|
| 17 |
+
n_ctx=4096, # याददाश्त (Context)
|
| 18 |
+
n_threads=2, # CPU Cores
|
| 19 |
+
verbose=False
|
| 20 |
+
)
|
| 21 |
+
|
| 22 |
+
# 3. सोचने वाला फंक्शन
|
| 23 |
+
def chat_function(message, history):
|
| 24 |
+
system_prompt = """You are a helpful AI assistant named Ahamad-Bot.
|
| 25 |
+
You answer questions accurately and concisely.
|
| 26 |
+
"""
|
| 27 |
+
|
| 28 |
+
# प्रॉम्प्ट तैयार करना
|
| 29 |
+
prompt = f"<|system|>\n{system_prompt}\n<|user|>\n{message}\n<|assistant|>\n"
|
| 30 |
+
|
| 31 |
+
output = llm(
|
| 32 |
+
prompt,
|
| 33 |
+
max_tokens=512, # जवाब की लंबाई
|
| 34 |
+
stop=["<|user|>", "<|end|>"],
|
| 35 |
+
echo=False
|
| 36 |
+
)
|
| 37 |
+
return output['choices'][0]['text']
|
| 38 |
+
|
| 39 |
+
# 4. इंटरफेस (App)
|
| 40 |
+
demo = gr.ChatInterface(
|
| 41 |
+
fn=chat_function,
|
| 42 |
+
title="🤖 Ahamad AI (DeepSeek Brain)",
|
| 43 |
+
description="यह मॉडल DeepSeek-R1 पर चल रहा है।",
|
| 44 |
+
examples=["राजस्थान की अगली राजधानी क्या हो सकती है?", "Python कैसे सीखें?"],
|
| 45 |
+
)
|
| 46 |
+
|
| 47 |
+
if __name__ == "__main__":
|
| 48 |
+
demo.launch()
|