rohith2157 commited on
Commit
aec37b7
·
verified ·
1 Parent(s): 1c1174b
Files changed (1) hide show
  1. app.py +35 -0
app.py ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from llama_cpp import Llama
3
+ from huggingface_hub import hf_hub_download
4
+
5
+ # --- SETTINGS ---
6
+ # This is the Qwen3-VL 8B model (Quantized to fit in Free Space)
7
+ REPO_ID = "Qwen/Qwen3-VL-8B-Instruct-GGUF"
8
+ FILENAME = "*q4_k_m.gguf"
9
+
10
+ print("⬇️ Downloading model... (This mimics 'ollama pull')")
11
+ try:
12
+ model_path = hf_hub_download(repo_id=REPO_ID, filename=FILENAME)
13
+ except:
14
+ # Fallback to Qwen2.5-VL if Qwen3 isn't fully indexed yet
15
+ print("⚠️ Qwen3 GGUF not found, falling back to Qwen2.5-VL")
16
+ model_path = hf_hub_download(repo_id="Qwen/Qwen2.5-VL-7B-Instruct-GGUF", filename="*q4_k_m.gguf")
17
+
18
+ print("✅ Model downloaded!")
19
+
20
+ # --- LOAD ENGINE ---
21
+ # n_gpu_layers=0 forces CPU mode (Free Tier)
22
+ llm = Llama(
23
+ model_path=model_path,
24
+ n_ctx=2048,
25
+ n_gpu_layers=0,
26
+ verbose=True
27
+ )
28
+
29
+ # --- CHAT UI ---
30
+ def chat(message, history):
31
+ prompt = f"<|im_start|>user\n{message}<|im_end|>\n<|im_start|>assistant\n"
32
+ output = llm(prompt, max_tokens=512, stop=["<|im_end|>"], echo=False)
33
+ return output['choices'][0]['text']
34
+
35
+ gr.ChatInterface(chat).launch(server_name="0.0.0.0", server_port=7860)