VJ-Rising commited on
Commit
31e97db
·
verified ·
1 Parent(s): 5f5090e

Updated Code

Browse files
Files changed (1) hide show
  1. app.py +14 -13
app.py CHANGED
@@ -1,22 +1,23 @@
1
  import gradio as gr
 
2
  from huggingface_hub import InferenceClient
3
 
4
  client = InferenceClient("Qwen/Qwen2.5-7B-Instruct")
5
 
6
- def random_response(message, history):
7
- messages = [{"role":"system", "content" : "You are an exceptionally unique and kind chatbot."}]
8
-
 
9
  if history:
10
  messages.extend(history)
11
- messages.append({"role":"user", "content":message})
12
-
13
- response = client.chat_completion(
14
- model="Qwen/Qwen2.5-7B-Instruct",
15
- messages=messages,
16
- max_tokens = 100
17
- )
18
- return response.choices[0].message.content.strip()
19
-
20
- chatbot = gr.ChatInterface(random_response, title = "Vanshika's First Chatbot")
21
 
 
22
  chatbot.launch()
 
1
  import gradio as gr
2
+
3
  from huggingface_hub import InferenceClient
4
 
5
  client = InferenceClient("Qwen/Qwen2.5-7B-Instruct")
6
 
7
+ def respond(message, history):
8
+ messages = [{"role": "system",
9
+ "content":"You are an emotional support chatbot. "
10
+ }]
11
  if history:
12
  messages.extend(history)
13
+ messages.append({"role":"user",
14
+ "content":message
15
+ })
16
+ response = " "
17
+ for msg in client.chat_completion(messages, max_tokens = 1000, temperature = 1, top_p = 0.5, stream = True):
18
+ token = msg.choices[0].delta.content
19
+ response += token
20
+ yield response
 
 
21
 
22
+ chatbot gr.ChatInterface(fn=respond, title = "Mind Matters", description = "_put this rn_", editable = True)
23
  chatbot.launch()