Spaces:
Runtime error
Runtime error
Update app.py
Browse files8 unmodified lines910111212131415161718171819202122222324242526272728292829303131323334352 unmodified lines383940404142434445463 unmodified lines5051525053545556575855596061586263606465666768698 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 token=os.getenv("HF_TOKEN"))
llm = Llama( model_path=model_path, n_ctx=512, # reduced to avoid OOM (important in 2026 Spaces) n_threads=1 # safer for low resources n_ctx=512, n_threads=1)
# =========================# CHAT FUNCTION# CHAT FUNCTION (MODERN FORMAT)# =========================def chat(prompt, history):def chat(message, history): # convert Gradio "messages" format safely messages = []
for user_msg, bot_msg in history: messages.append({"role": "user", "content": user_msg}) messages.append({"role": "assistant", "content": bot_msg}) for msg in history: if isinstance(msg, dict): messages.append(msg)
messages.append({"role": "user", "content": prompt}) messages.append({"role": "user", "content": message})
output = llm.create_chat_completion( messages=messages,2 unmodified lines )
response = output["choices"][0]["message"]["content"] history.append((prompt, response))
history.append({"role": "user", "content": message}) history.append({"role": "assistant", "content": response})
return "", history
3 unmodified lineswith gr.Blocks() as demo: gr.Markdown("# 🧠 Qwen GGUF AI (Living Legend Build)")
chatbot = gr.Chatbot() 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) clear.click(lambda: [], None, chatbot, queue=False)
# =========================# LAUNCH# LAUNCH (SPACE SAFE)# =========================demo.launch()demo.queue()
demo.launch( server_name="0.0.0.0", server_port=7860)app.py+23-14