Spaces:
Runtime error
Runtime error
Update app.py
Browse files18 unmodified lines1920212222232425262526272829303132282930353132333435363742383940414248434445462 unmodified lines4950515253545556575818 unmodified lines)
# =========================# CHAT FUNCTION (MODERN FORMAT)# CHAT FUNCTION (GRADIO 4 STYLE)# =========================def chat(message, history): # convert Gradio "messages" format safely messages = [] # history is list of dicts in Gradio 4 history = history or []
for msg in history: if isinstance(msg, dict): messages.append(msg)
messages.append({"role": "user", "content": message}) history.append({"role": "user", "content": message})
output = llm.create_chat_completion( messages=messages, messages=history, max_tokens=300, temperature=0.7 )
response = output["choices"][0]["message"]["content"]
history.append({"role": "user", "content": message}) history.append({"role": "assistant", "content": response})
return "", history
# =========================# GRADIO UI# GRADIO UI (GRADIO 4)# =========================with gr.Blocks() as demo: gr.Markdown("# 🧠 Qwen GGUF AI (Living Legend Build)")2 unmodified lines 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)
# =========================app.py+8-11