File size: 1,174 Bytes
840e990
f13ef36
e08b5b2
 
 
 
 
d5c35d5
e08b5b2
 
 
d5c35d5
e08b5b2
d5c35d5
e08b5b2
 
 
 
 
 
 
 
 
 
 
 
 
d5c35d5
e08b5b2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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