delphine-cmd commited on
Commit
44a85af
·
verified ·
1 Parent(s): f327c2f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -19
app.py CHANGED
@@ -1,26 +1,22 @@
1
  import gradio as gr
2
  from transformers import pipeline
3
 
4
- # Load the Zephyr model from Hugging Face
5
- pipe = pipeline("text-generation", model="HuggingFaceH4/zephyr-7b-beta")
6
 
7
- def chat_with_zephyr(message, history):
8
- # Combine the chat history into a context
9
- context = ""
10
- for user, bot in history:
11
- context += f"User: {user}\nAssistant: {bot}\n"
12
- context += f"User: {message}\nAssistant:"
 
13
 
14
- # Generate a response
15
- output = pipe(context, max_new_tokens=200, do_sample=True, temperature=0.7)
16
- reply = output[0]["generated_text"].split("Assistant:")[-1].strip()
17
- return reply
18
-
19
- # Build chat UI
20
- chatbot = gr.ChatInterface(
21
- fn=chat_with_zephyr,
22
- title="GIMPA AI Assistant",
23
- description="Ask me anything! Powered by Zephyr-7B model.",
24
  )
25
 
26
- chatbot.launch()
 
1
  import gradio as gr
2
  from transformers import pipeline
3
 
4
+ # ⚡ Use a smaller model — much faster than Zephyr
5
+ chatbot = pipeline("conversational", model="microsoft/DialoGPT-medium")
6
 
7
+ def chat(user_input, history=[]):
8
+ from transformers import Conversation
9
+ conversation = Conversation(user_input)
10
+ conversation = chatbot(conversation)
11
+ response = conversation.generated_responses[-1]
12
+ history.append((user_input, response))
13
+ return history, history
14
 
15
+ # 🧩 Simple Gradio chat UI
16
+ demo = gr.ChatInterface(
17
+ fn=chat,
18
+ title="GIMPA Assistant 💬",
19
+ description="Fast AI assistant (CPU friendly)",
 
 
 
 
 
20
  )
21
 
22
+ demo.launch()