tonicstl commited on
Commit
b3567b2
·
verified ·
1 Parent(s): 8107618

Update app.py

Browse files

turned echo into friendly chatbot

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