diyapg commited on
Commit
5080a14
·
verified ·
1 Parent(s): 91f640a

Update app.py

Browse files

turn random into general chatbot

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