Spaces:
Runtime error
Runtime error
Update app.py
Browse files8 unmodified lines9101112131415161718192021222324252627282930313233342 unmodified lines373839404142433 unmodified lines47484950515253545556575859608 unmodified linesmodel_path = hf_hub_download(repo_id="Mikecode123/ALX",filename="qwen2-1_5b-instruct-q4_0.gguf",token=os.getenv("HF_TOKEN") # secure access)llm = Llama(model_path=model_path,n_ctx=512, # reduced to avoid OOM (important in 2026 Spaces)n_threads=1 # safer for low resources)# =========================# CHAT FUNCTION# =========================def chat(prompt, history):messages = []for user_msg, bot_msg in history:messages.append({"role": "user", "content": user_msg})messages.append({"role": "assistant", "content": bot_msg})messages.append({"role": "user", "content": prompt})output = llm.create_chat_completion(messages=messages,2 unmodified lines)response = output["choices"][0]["message"]["content"]history.append((prompt, response))return "", history3 unmodified lineswith gr.Blocks() as demo:gr.Markdown("# 🧠 Qwen GGUF AI (Living Legend Build)")chatbot = gr.Chatbot()msg = gr.Textbox(label="Ask your AI")clear = gr.Button("Clear")msg.submit(chat, [msg, chatbot], [msg, chatbot])clear.click(lambda: [], None, chatbot)# =========================# LAUNCH# =========================demo.launch()8 unmodified lines910111213141516171819202122232425262728293031323334352 unmodified lines3839404142434445463 unmodified lines50515253545556575859606162636465666768698 unmodified linesmodel_path = hf_hub_download(repo_id="Mikecode123/ALX",filename="qwen2-1_5b-instruct-q4_0.gguf",token=os.getenv("HF_TOKEN"))llm = Llama(model_path=model_path,n_ctx=512,n_threads=1)# =========================# CHAT FUNCTION (MODERN FORMAT)# =========================def chat(message, history):# convert Gradio "messages" format safelymessages = []for msg in history:if isinstance(msg, dict):messages.append(msg)messages.append({"role": "user", "content": message})output = llm.create_chat_completion(messages=messages,2 unmodified lines)response = output["choices"][0]["message"]["content"]history.append({"role": "user", "content": message})history.append({"role": "assistant", "content": response})return "", history3 unmodified lineswith gr.Blocks() as demo:gr.Markdown("# 🧠 Qwen GGUF AI (Living Legend Build)")chatbot = gr.Chatbot(type="messages")msg = gr.Textbox(label="Ask your AI")clear = gr.Button("Clear")msg.submit(chat, [msg, chatbot], [msg, chatbot])clear.click(lambda: [], None, chatbot, queue=False)# =========================# LAUNCH (SPACE SAFE)# =========================demo.queue()demo.launch(server_name="0.0.0.0",server_port=7860)
app.py+23-14