Bndo commited on
Commit
e08b5b2
·
verified ·
1 Parent(s): 379ec41

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -16
app.py CHANGED
@@ -1,22 +1,29 @@
1
  import gradio as gr
2
- from transformers import pipeline
3
 
4
- # Use a simple, fast Hugging Face model
5
- chatbot_pipeline = pipeline("text-generation", model="HuggingFaceH4/zephyr-7b-alpha")
 
 
 
6
 
7
- # Function to generate a chatbot response
8
- def chat_response(user_input):
9
- response = chatbot_pipeline(user_input, max_length=100)[0]["generated_text"]
10
- return response
11
 
12
- # Gradio UI
13
- demo = gr.Interface(
14
- fn=chat_response,
15
- inputs="text",
16
- outputs="text",
17
- title="🤖 Bandar AI Model"
18
- )
19
 
20
- # Run on Hugging Face Spaces
 
 
 
 
 
 
 
 
 
 
 
 
21
  if __name__ == "__main__":
22
- demo.launch()
 
1
  import gradio as gr
 
2
 
3
+ # Define the chatbot function
4
+ def chat_response(history, user_input):
5
+ """Handles chatbot interactions."""
6
+ if not user_input.strip():
7
+ return history + [("User", user_input), ("Bot", "Please enter a valid message.")]
8
 
9
+ response = f"You said: {user_input}" # Replace this with actual chatbot logic (e.g., OpenAI API)
10
+ history.append({"role": "user", "content": user_input})
11
+ history.append({"role": "assistant", "content": response})
 
12
 
13
+ return history, ""
 
 
 
 
 
 
14
 
15
+ # Initialize Gradio chatbot with the correct type
16
+ with gr.Blocks() as demo:
17
+ gr.Markdown("## 🚀 AI Bandar - Powered by Gradio")
18
+
19
+ chatbot = gr.Chatbot(type="messages") # ✅ Fix: Use 'messages' format
20
+ user_input = gr.Textbox(label="Your Message")
21
+ submit_button = gr.Button("Send")
22
+
23
+ # Button click or Enter key submits the message
24
+ submit_button.click(chat_response, inputs=[chatbot, user_input], outputs=[chatbot, user_input])
25
+ user_input.submit(chat_response, inputs=[chatbot, user_input], outputs=[chatbot, user_input])
26
+
27
+ # Run the Gradio app
28
  if __name__ == "__main__":
29
+ demo.launch(share=True) # 🚀 Allows sharing via public Gradio link