floralwave commited on
Commit
2e7e87b
·
verified ·
1 Parent(s): 848b305

Update app.py

Browse files

turned that chatbot of random choices into more dynamic conversation added access token

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