Ire-O commited on
Commit
620f406
·
verified ·
1 Parent(s): 2598fe4

General chatbot update

Browse files
Files changed (1) hide show
  1. app.py +21 -1
app.py CHANGED
@@ -1,5 +1,8 @@
1
  import gradio as gr # imports the gradio library
2
  import random
 
 
 
3
 
4
  # returns the message back to the user
5
  def echo(message, history):
@@ -7,11 +10,28 @@ def echo(message, history):
7
 
8
  # returns yes or no back to the user
9
  def yes_or_no(message, history):
 
10
  responses = ["Yes","No"]
11
  return random.choice(responses) #randomly returns one
12
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13
  #print("Hello world!") #prints in the logs
14
 
15
- chatbot = gr.ChatInterface(yes_or_no, type="messages", title="chatbot bestie") # chatbout ui - history & input
16
 
17
  chatbot.launch() # lauches chatbot
 
1
  import gradio as gr # imports the gradio library
2
  import random
3
+ from huggingface_hub import InferenceClient
4
+
5
+ client = InferenceClient("microsoft/phi-4")
6
 
7
  # returns the message back to the user
8
  def echo(message, history):
 
10
 
11
  # returns yes or no back to the user
12
  def yes_or_no(message, history):
13
+
14
  responses = ["Yes","No"]
15
  return random.choice(responses) #randomly returns one
16
 
17
+ # returns a message back to the user
18
+ def response(message, history):
19
+
20
+ messages = [{"role":"system","content":"You are a friendly chatbot :)"}]
21
+
22
+ if history:
23
+ messages.extend(history)
24
+
25
+ messages.append({"role":"user", "content":message})
26
+ responses = client.chat_completion(
27
+ messages,
28
+ max_tokens = 100 #chunks of material
29
+ )
30
+
31
+ return response['choices'][0]['message']['content'].strip() #returns response from library
32
+
33
  #print("Hello world!") #prints in the logs
34
 
35
+ chatbot = gr.ChatInterface(response, type="messages", title="chatbot bestie") # chatbout ui - history & input
36
 
37
  chatbot.launch() # lauches chatbot