Spaces:
Sleeping
Sleeping
Update app.py
Browse files13 unmodified lines14151617181920212223242526272829301 unmodified line32333435363738394041424344454618 unmodified lines656667686970717273747576777 unmodified lines85868788899091929394959613 unmodified linesclient = Groq(api_key=api_key)# -------------------------------------------------# Chat Logic# -------------------------------------------------def chat(user_input, history):if not user_input or not user_input.strip():return history, ""messages = []for u, a in history:messages.append({"role": "user", "content": u})messages.append({"role": "assistant", "content": a})messages.append({"role": "user", "content": user_input})try:1 unmodified linemodel="llama-3.3-70b-versatile",messages=messages,)response = completion.choices[0].message.contentexcept Exception as e:response = f"⚠️ Error: {str(e)}"history.append((user_input, response))return history, ""# -------------------------------------------------# Theme & CSS (Gradio 6 compatible)# -------------------------------------------------theme = gr.themes.Soft(primary_hue="blue",18 unmodified linesgr.Markdown("""# 🤖 Groq AI Chatbot**Fast • Responsive • Human-Centered Interface**""")chatbot = gr.Chatbot(height=420,show_label=False)with gr.Row():7 unmodified lineswith gr.Row():clear_btn = gr.Button("Clear Chat", variant="secondary")# Interactionssend_btn.click(chat, [user_input, chatbot], [chatbot, user_input])user_input.submit(chat, [user_input, chatbot], [chatbot, user_input])clear_btn.click(lambda: [], None, chatbot)# -------------------------------------------------# Launch (theme & css moved here for Gradio 6)# -------------------------------------------------demo.launch(theme=theme, css=custom_css)13 unmodified lines14151617181920212223242526271 unmodified line2930313233343536373839404142434418 unmodified lines63646566676869707172737475767 unmodified lines848586878889909113 unmodified linesclient = Groq(api_key=api_key)# -------------------------------------------------# Chat Logic (Gradio 6 compatible)# -------------------------------------------------def chat(user_input, history):if not user_input or not user_input.strip():return history, ""# history is already a list of {role, content}messages = history.copy()messages.append({"role": "user", "content": user_input})try:1 unmodified linemodel="llama-3.3-70b-versatile",messages=messages,)assistant_reply = completion.choices[0].message.contentexcept Exception as e:assistant_reply = f"⚠️ Error: {str(e)}"messages.append({"role": "assistant", "content": assistant_reply})return messages, ""# -------------------------------------------------# Theme & CSS# -------------------------------------------------theme = gr.themes.Soft(primary_hue="blue",18 unmodified linesgr.Markdown("""# 🤖 Groq AI Chatbot**Fast • Responsive • HCI-Friendly Interface**""")chatbot = gr.Chatbot(height=420,show_label=False,type="messages" # 🔴 IMPORTANT FIX)with gr.Row():7 unmodified lineswith gr.Row():clear_btn = gr.Button("Clear Chat", variant="secondary")send_btn.click(chat, [user_input, chatbot], [chatbot, user_input])user_input.submit(chat, [user_input, chatbot], [chatbot, user_input])clear_btn.click(lambda: [], None, chatbot)demo.launch(theme=theme, css=custom_css)
app.py+13-18