clarissah commited on
Commit
e42d9e6
·
verified ·
1 Parent(s): 6456e0a

Practice for Lesson 11 of Generative AI

Browse files
Files changed (1) hide show
  1. app.py +18 -1
app.py CHANGED
@@ -1,12 +1,29 @@
1
  import gradio as gr
2
  import random
 
3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
  def echo(message, history):
5
  choices = ["yes", "ummmmm no no no", "sure", ".....I think you need to rethink your choices", "you deserve a sweet treat", "I don't think so"]
6
  #use random to select one of these choices
7
  random_message = random.choice(choices)
8
  return random_message
9
 
10
- chatbot = gr.ChatInterface(echo, type = "messages", theme = "shivi/calm_seafoam")
11
 
12
  chatbot.launch()
 
1
  import gradio as gr
2
  import random
3
+ from huggingface_hub import InferenceClient
4
 
5
+ client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
6
+
7
+ def respond(message, history):
8
+
9
+ messages = ({"role": "system", "content": "You are a friendly chatbot."})
10
+ if history:
11
+ messages.extend(history)
12
+
13
+ messages.append({"role": "user", "content" : message})
14
+
15
+ response = client.chat_completion(messages, max_token = 100)
16
+
17
+ print(response ["choices"][0]["message"]["content"].strip())
18
+
19
+ return response ["choices"][0]["message"]["content"].strip()
20
+
21
  def echo(message, history):
22
  choices = ["yes", "ummmmm no no no", "sure", ".....I think you need to rethink your choices", "you deserve a sweet treat", "I don't think so"]
23
  #use random to select one of these choices
24
  random_message = random.choice(choices)
25
  return random_message
26
 
27
+ chatbot = gr.ChatInterface(respond, type = "messages", theme = "shivi/calm_seafoam")
28
 
29
  chatbot.launch()