import gradio as gr from llama_cpp import Llama from huggingface_hub import hf_hub_download # --- THIS IS THE DOWNLOAD STEP --- # The Space will download the model automatically when it starts. # We use Bartowski's optimized version which is small and fast. repo_id = "bartowski/Qwen2.5-VL-7B-Instruct-GGUF" filename = "Qwen2.5-VL-7B-Instruct-Q4_K_M.gguf" print(f"⬇️ Downloading {filename} from Hugging Face Cloud...") model_path = hf_hub_download( repo_id=repo_id, filename=filename, repo_type="model" ) print("✅ Download Complete! Loading model...") # --- LOAD THE MODEL --- # n_gpu_layers=0 means we force it to run on the CPU (Free Tier) llm = Llama( model_path=model_path, n_ctx=4096, # How much it remembers n_gpu_layers=0, # 0 = CPU verbose=True ) # --- CHAT INTERFACE --- def chat(message, history): # Qwen-specific format prompt = f"<|im_start|>user\n{message}<|im_end|>\n<|im_start|>assistant\n" output = llm( prompt, max_tokens=512, stop=["<|im_end|>"], echo=False ) return output['choices'][0]['text'] gr.ChatInterface(chat).launch(server_name="0.0.0.0", server_port=7860)