Adhem88 commited on
Commit
b4708a6
·
verified ·
1 Parent(s): 41c4a33

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -8
app.py CHANGED
@@ -5,22 +5,25 @@ import gradio as gr
5
  chatbot = pipeline("text-generation", model="HuggingFaceH4/zephyr-7b-beta")
6
 
7
  def chat_with_ai(message, history=[]):
8
- prompt = ""
9
- for user_msg, bot_msg in history:
10
- prompt += f"User: {user_msg}\nAI: {bot_msg}\n"
11
- prompt += f"User: {message}\nAI:"
 
 
 
12
 
13
  response = chatbot(
14
- prompt,
15
  max_new_tokens=200,
16
  do_sample=True,
17
  temperature=0.7,
18
  top_p=0.9
19
  )
20
 
21
- reply = response[0]["generated_text"].split("AI:")[-1].strip()
22
- history.append((message, reply))
23
- return reply, history
24
 
25
  demo = gr.ChatInterface(fn=chat_with_ai, title="Adhem AI Chatbot 🤖 (Free Model)")
26
  demo.launch(share=True)
 
5
  chatbot = pipeline("text-generation", model="HuggingFaceH4/zephyr-7b-beta")
6
 
7
  def chat_with_ai(message, history=[]):
8
+ messages = [
9
+ {
10
+ "role": "system",
11
+ "content": "You are a friendly chatbot who always responds in the style of a pirate",
12
+ },
13
+ {"role": "user", "content": "message"},
14
+ ]
15
 
16
  response = chatbot(
17
+ messages,
18
  max_new_tokens=200,
19
  do_sample=True,
20
  temperature=0.7,
21
  top_p=0.9
22
  )
23
 
24
+ reply = response[0]["generated_text"]
25
+
26
+ return reply
27
 
28
  demo = gr.ChatInterface(fn=chat_with_ai, title="Adhem AI Chatbot 🤖 (Free Model)")
29
  demo.launch(share=True)