import gradio as gr from huggingface_hub import hf_hub_download from llama_cpp import Llama MODEL_REPO = "bartowski/Phi-3-mini-4k-instruct-GGUF" MODEL_FILE = "Phi-3-mini-4k-instruct-Q4_K_M.gguf" print("Downloading model...") model_path = hf_hub_download( repo_id=MODEL_REPO, filename=MODEL_FILE ) print("Loading model...") llm = Llama( model_path=model_path, n_ctx=2048, n_threads=4, verbose=False ) SYSTEM_PROMPT = """ You are a senior software engineer. You specialize in: - Python - JavaScript - TypeScript - PHP - Pawn/OpenMP - SQL - C++ - Rust Always: - Explain clearly - Generate complete code - Follow best practices """ def chat(message, history): conversation = "" for user, assistant in history: conversation += f"User: {user}\n" conversation += f"Assistant: {assistant}\n" prompt = f""" {SYSTEM_PROMPT} {conversation} User: {message} Assistant: """ output = llm( prompt, max_tokens=256, temperature=0.2, top_p=0.95, stop=["User:"] ) return output["choices"][0]["text"].strip() demo = gr.ChatInterface( fn=chat, title="AI Coding Assistant", description="Running locally on Hugging Face CPU Basic" ) demo.launch()