antoinette-f commited on
Commit
ea51f49
·
verified ·
1 Parent(s): fc10c4b

changed random yes/no chatbot into general chatbot

Browse files

turned that chatbot of random choices into more dynamic conversation, added token to access model.

Files changed (1) hide show
  1. app.py +18 -5
app.py CHANGED
@@ -1,12 +1,25 @@
1
  import gradio as gr
2
- import random
3
 
4
- def respond_yes_no_randomly(message,history): #function to return the history of messages sent
5
- responses = ["Yes", "No"]
6
- return random.choice(responses)
7
 
 
 
8
 
9
- chatbot = gr.ChatInterface(respond_yes_no_randomly, type="messages", title = "Yes/No Bot")
 
 
 
 
 
 
 
 
 
 
 
 
 
10
  # chatbot UI - conversation history and user input
11
 
12
  chatbot.launch()
 
1
  import gradio as gr
2
+ from huggingface_hub import InferenceClient
3
 
4
+ client = InferenceClient("microsoft/phi-4")
 
 
5
 
6
+ def respond(message,history): #function to return the history of messages sent
7
+ messages[{"role": "system", "content": "You are a friendly chatbot!"}]
8
 
9
+ if history:
10
+ messages.extend(history)
11
+
12
+ messages.append({"role": "user", "content":message})
13
+
14
+
15
+ responses = client.chat_completion(
16
+ messages,
17
+ max_token = 568
18
+ )
19
+ return response['choices'][0]['message']['content'].strip()
20
+
21
+
22
+ chatbot = gr.ChatInterface(respond, type="messages", title = "Friendly chatbot")
23
  # chatbot UI - conversation history and user input
24
 
25
  chatbot.launch()