Spaces:
Runtime error
Runtime error
Update app.py
Browse files3 unmodified lines456789108 unmodified lines1920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465663 unmodified linesfrom huggingface_hub import hf_hub_download# =========================# LOAD MODEL FROM HF REPO# =========================model_path = hf_hub_download(repo_id="Mikecode123/ALX",8 unmodified lines)# =========================# CHAT FUNCTION (GRADIO 4 STYLE)# =========================def chat(message, history):# history is list of dicts in Gradio 4history = history or []history.append({"role": "user", "content": message})output = llm.create_chat_completion(messages=history,max_tokens=300,temperature=0.7)response = output["choices"][0]["message"]["content"]history.append({"role": "assistant", "content": response})return "", history# =========================# GRADIO UI (GRADIO 4)# =========================with 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")# send messagemsg.submit(chat, [msg, chatbot], [msg, chatbot])# clear chatclear.click(lambda: [], None, chatbot, queue=False)# =========================# LAUNCH (SPACE SAFE)# =========================demo.queue()demo.launch(server_name="0.0.0.0",server_port=7860)3 unmodified lines456789108 unmodified lines19202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879803 unmodified linesfrom huggingface_hub import hf_hub_download# =========================# LOAD MODEL# =========================model_path = hf_hub_download(repo_id="Mikecode123/ALX",8 unmodified lines)# =========================# SAFE CHAT FUNCTION# =========================def chat(prompt, history):history = history or []messages = []# Convert Gradio history safely (tuple-based)for item in history:if isinstance(item, tuple) and len(item) == 2:user_msg, bot_msg = itemmessages.append({"role": "user","content": str(user_msg)})messages.append({"role": "assistant","content": str(bot_msg)})# Add current messagemessages.append({"role": "user","content": str(prompt)})# Call modeloutput = llm.create_chat_completion(messages=messages,max_tokens=300,temperature=0.7)response = output["choices"][0]["message"]["content"]history.append((prompt, response))return "", history# =========================# UI (GRADIO SAFE MODE)# =========================with gr.Blocks() as demo:gr.Markdown("# 🧠 Qwen GGUF AI (Living Legend System)")chatbot = gr.Chatbot() # Gradio 3 safe modemsg = 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 SAFE# =========================demo.queue()demo.launch(server_name="0.0.0.0", server_port=7860)
app.py+32-18