import gradio as gr # Define the chatbot function def chat_response(history, user_input): """Handles chatbot interactions.""" if not user_input.strip(): return history + [("User", user_input), ("Bot", "Please enter a valid message.")] response = f"You said: {user_input}" # Replace this with actual chatbot logic (e.g., OpenAI API) history.append({"role": "user", "content": user_input}) history.append({"role": "assistant", "content": response}) return history, "" # Initialize Gradio chatbot with the correct type with gr.Blocks() as demo: gr.Markdown("## 🚀 AI Bandar - Powered by Gradio") chatbot = gr.Chatbot(type="messages") # ✅ Fix: Use 'messages' format user_input = gr.Textbox(label="Your Message") submit_button = gr.Button("Send") # Button click or Enter key submits the message submit_button.click(chat_response, inputs=[chatbot, user_input], outputs=[chatbot, user_input]) user_input.submit(chat_response, inputs=[chatbot, user_input], outputs=[chatbot, user_input]) # Run the Gradio app if __name__ == "__main__": demo.launch(share=True) # 🚀 Allows sharing via public Gradio link