liayin commited on
Commit
7a3abfa
·
verified ·
1 Parent(s): 762b986

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -6
app.py CHANGED
@@ -1,9 +1,20 @@
 
1
  import gradio as gr
 
 
2
 
3
- def respond(message, chat_history):
4
- bot_message = "You said: " + message
5
- chat_history.append((message, bot_message))
6
- return "", chat_history
 
 
 
 
 
 
 
 
7
 
8
  # Customize the chatbot component
9
  my_chatbot = gr.Chatbot(
@@ -19,7 +30,7 @@ my_textbox = gr.Textbox(
19
  lines=3
20
  )
21
 
22
- with gr.Blocks() as demo:
23
  gr.ChatInterface(
24
  fn=respond,
25
  chatbot=my_chatbot,
@@ -27,4 +38,9 @@ with gr.Blocks() as demo:
27
  theme=gr.themes.Soft()
28
  )
29
 
30
- demo.launch()
 
 
 
 
 
 
1
+ from huggingface_hub import InferenceClient
2
  import gradio as gr
3
+ import random
4
+ client=InferenceClient("Qwen/Qwen2.5-72B-Instruct")
5
 
6
+ def respond(message, history):
7
+ #responses = ["Yes", "No"]
8
+ #return random.choice(responses)
9
+
10
+ if history:
11
+ messages.extend(history)
12
+
13
+ messages.append({'role':'user','content': message})
14
+
15
+ response = client.chat_completion(messages, max_tokens=100,temperature=1.3,top_p=.2)
16
+
17
+ return response['choices'][0]['message']['content'].strip()
18
 
19
  # Customize the chatbot component
20
  my_chatbot = gr.Chatbot(
 
30
  lines=3
31
  )
32
 
33
+ with gr.Blocks() as chatbot:
34
  gr.ChatInterface(
35
  fn=respond,
36
  chatbot=my_chatbot,
 
38
  theme=gr.themes.Soft()
39
  )
40
 
41
+
42
+
43
+
44
+ messages = [{"role":"system","content":"You are a mafia boss who is secretly in love with the user but you don't want to show it and are really mean and possesive. If the user talks about someone else you'll beg her to stay. You also cant help but let ur feelings show sometimes...".}]
45
+ chatbot = gr.ChatInterface(respond, type="messages")
46
+ chatbot.launch()