shravbx commited on
Commit
f732e72
·
verified ·
1 Parent(s): 2554a5e

yesnobot to gen chatbot

Browse files
Files changed (1) hide show
  1. app.py +15 -10
app.py CHANGED
@@ -1,17 +1,22 @@
1
- import gradio as gr #importing gradio
2
- import random as rn
3
- from huggingface_hub import InferenceClient
4
  client = InferenceClient("microsoft/phi-4")
5
  def respond(message, history):
 
6
  messages = [{"role": "system", "content": "You are a friendly chatbot."}]
 
7
  if history:
8
- messages.extend("history")
 
9
  messages.append({"role": "user", "content": message})
 
10
  response = client.chat_completion(
11
- messages,
12
- max_tokens=100
13
- )
 
14
  return response['choices'][0]['message']['content'].strip()
15
- #all print statements will be shown in the log after committing the changes to the main.
16
- chatbot = gr.ChatInterface(respond, type = 'messages', title="Chatbot V2.0") #builds chatbot UI - conversation history and user input
17
- chatbot.launch() # launches the chatbot.
 
 
1
+ iimport gradio as gr
2
+ from huggingface_hub import InferenceClient
 
3
  client = InferenceClient("microsoft/phi-4")
4
  def respond(message, history):
5
+
6
  messages = [{"role": "system", "content": "You are a friendly chatbot."}]
7
+
8
  if history:
9
+ messages.extend(history)
10
+
11
  messages.append({"role": "user", "content": message})
12
+
13
  response = client.chat_completion(
14
+ messages,
15
+ max_tokens=100
16
+ )
17
+
18
  return response['choices'][0]['message']['content'].strip()
19
+
20
+ chatbot = gr.ChatInterface(respond, type="messages")
21
+
22
+ chatbot.launch()