AmbikaP commited on
Commit
eacba31
·
verified ·
1 Parent(s): d280812

new Update

Browse files
Files changed (1) hide show
  1. app.py +17 -1
app.py CHANGED
@@ -1,15 +1,31 @@
1
  import gradio as gr
2
  import random
 
3
  # import lines go at the top! any libraries I need to import
4
 
 
 
 
5
  #def echo(message, history):
6
  #return message
7
 
 
 
 
 
 
 
 
 
 
 
 
 
8
  def yes_or_no(message,history):
9
  return random.choice(["absolutely NOT.","now why would you even ask that", "this is not what I meant when i said do it for the lore..","do it for the lore!", "+1000 aura if you do","yes PLEASE", "i mean you do you ig..","i mean yolo"])
10
 
11
  print("Hello world!")
12
- chatbot = gr.ChatInterface(yes_or_no, type="messages", description = "Feeling impulsive? Let's see if you shld ACC go thru with it", title = "Magic 8 Ball Chatbot", theme = "monochrome")
13
  # defining my chatbot so that the user can interact, see their convo history and send new messages
14
 
15
  chatbot.launch()
 
1
  import gradio as gr
2
  import random
3
+ from huggingface_hub import InferenceClient
4
  # import lines go at the top! any libraries I need to import
5
 
6
+ client = InferenceClient("microsoft/phi-4")
7
+ #CREATE AN INSTANCE OF INFERENCE CLIENT THAT'S CONNECTED TO THE MICROSOFT PHI GENERATION MODEL
8
+
9
  #def echo(message, history):
10
  #return message
11
 
12
+ def respond(message, history):
13
+ messages = [{"role": "system", "content" : "You are a friendly chatbot."}]
14
+ if history:
15
+ messages.extent(history) #conversation adds messages to the history
16
+ messages.append({"role": "user", "content": message})
17
+ response = client.chat_completion(
18
+ messages, #parameters
19
+ max_tokens = 100 #determines how long the message will be
20
+ )
21
+
22
+ return response['choices'][0]['message']['content'].strip()
23
+
24
  def yes_or_no(message,history):
25
  return random.choice(["absolutely NOT.","now why would you even ask that", "this is not what I meant when i said do it for the lore..","do it for the lore!", "+1000 aura if you do","yes PLEASE", "i mean you do you ig..","i mean yolo"])
26
 
27
  print("Hello world!")
28
+ chatbot = gr.ChatInterface(respond , type = "messages")
29
  # defining my chatbot so that the user can interact, see their convo history and send new messages
30
 
31
  chatbot.launch()