| import gradio as gr |
|
|
| |
| 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}" |
| history.append({"role": "user", "content": user_input}) |
| history.append({"role": "assistant", "content": response}) |
|
|
| return history, "" |
|
|
| |
| with gr.Blocks() as demo: |
| gr.Markdown("## π AI Bandar - Powered by Gradio") |
|
|
| chatbot = gr.Chatbot(type="messages") |
| user_input = gr.Textbox(label="Your Message") |
| submit_button = gr.Button("Send") |
|
|
| |
| 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]) |
|
|
| |
| if __name__ == "__main__": |
| demo.launch(share=True) |