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