aaliyah789 commited on
Commit
1e0f4bc
·
verified ·
1 Parent(s): f5f00e3

turned random into general chatbot

Browse files
Files changed (1) hide show
  1. app.py +19 -6
app.py CHANGED
@@ -1,12 +1,25 @@
1
  import gradio as gr
2
- import random
3
 
4
- def respond_yes_no_randomly(message, history):
5
- responses = ["Yes", "No"]
6
- return random.choice(responses)
7
 
8
- print("Hello, world!")
9
 
10
- chatbot = gr.ChatInterface(respond_yes_no_randomly, type = "messages", title = "Yes No Bot") #chatbot UI - coversation 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):
7
 
8
+ messages = [{"role": "system", "content": "You are a friendly chatbot!"}]
9
+
10
+ if history:
11
+ messages.extend(history)
12
+
13
+ messages.append({"role": "user", "content":message})
14
+
15
+
16
+ response = client.chat_completion(
17
+ meesages,
18
+ max_token=100
19
+ )
20
+ return response['choices'][0]['message']['content'].strip()
21
+
22
+
23
+ chatbot = gr.ChatInterface(respond, type = "messages", title = "Friendly chatbot") #chatbot UI - coversation history and user input
24
 
25
  chatbot.launch()