UserPotato12397 commited on
Commit
bdd0c15
·
verified ·
1 Parent(s): 98f75ab

Lesson 11 -> Practice for generative AI

Browse files
Files changed (1) hide show
  1. app.py +17 -1
app.py CHANGED
@@ -1,6 +1,22 @@
1
  import gradio as gr
2
  import random
 
3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
  def random_message(message, history):
5
  choices = [
6
  "It is certain",
@@ -27,6 +43,6 @@ def random_message(message, history):
27
  chat_answer = random.choice(choices)
28
  return chat_answer
29
 
30
- chatbot = gr.ChatInterface(random_message, type = "messages", title = "Your Virtual 8 Ball", description = "<center>Ask me any question and I will answer.</center>")
31
 
32
  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
+ messages = [{"role": "system", "content": "You are a friendly chatbot."}]
9
+ if history:
10
+ messages.extend(history)
11
+
12
+ message.appened({"role": "user", "content": message})
13
+
14
+ response = client.chat_completion(messages, max_tokens = 100)
15
+
16
+ print(response['choices'][0]['message']['content'].strip())
17
+
18
+ return response['choices'][0]['message']['content'].strip()
19
+
20
  def random_message(message, history):
21
  choices = [
22
  "It is certain",
 
43
  chat_answer = random.choice(choices)
44
  return chat_answer
45
 
46
+ chatbot = gr.ChatInterface(respond, type = "messages")
47
 
48
  chatbot.launch()