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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -25
app.py CHANGED
@@ -1,34 +1,21 @@
1
- import os
2
- os.system("pip install transformers torch accelerate gradio") # Install dependencies
3
-
4
  import gradio as gr
5
  from transformers import pipeline
6
 
7
- # Load the Hugging Face model
8
- chatbot_pipeline = pipeline("text-generation", model="mistralai/Mistral-7B-v0.1", max_new_tokens=100)
9
-
10
- # Chatbot function
11
- def chat_response(history, user_input):
12
- if not user_input.strip():
13
- return history + [{"role": "user", "content": user_input}, {"role": "assistant", "content": "Please enter a valid message."}], ""
14
-
15
- bot_reply = chatbot_pipeline(user_input)[0]["generated_text"]
16
 
17
- history.append({"role": "user", "content": user_input})
18
- history.append({"role": "assistant", "content": bot_reply})
19
-
20
- return history, ""
21
 
22
  # Gradio UI
23
- with gr.Blocks() as demo:
24
- gr.Markdown("## 🤖 AI Bandar - Powered by Hugging Face")
25
-
26
- chatbot = gr.Chatbot(type="messages")
27
- user_input = gr.Textbox(label="Your Message")
28
- submit_button = gr.Button("Send")
29
-
30
- submit_button.click(chat_response, inputs=[chatbot, user_input], outputs=[chatbot, user_input])
31
- user_input.submit(chat_response, inputs=[chatbot, user_input], outputs=[chatbot, user_input])
32
 
33
  # Run on Hugging Face Spaces
34
  if __name__ == "__main__":
 
 
 
 
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__":