Pengi5659 commited on
Commit
e813b91
·
verified ·
1 Parent(s): 837a995

practice Lesson for gerenative AI

Browse files
Files changed (1) hide show
  1. app.py +17 -2
app.py CHANGED
@@ -1,12 +1,27 @@
1
  import gradio as gr
2
  import random as rd
 
3
 
4
- def echo (message, history):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
  eight_ball_answers = ["yes","no","ehhh probably not the best idea","Sure why not!","idk","i seems not","hahahaha... no","yes of course!"]
6
  random_choice = rd.choice(eight_ball_answers)
7
  return random_choice
8
 
9
- chatbot = gr.ChatInterface(echo, type = "messages", title = "Rando Bot", description = "<center>Try your luck with this Rando Bot!")
10
 
11
  chatbot.launch()
12
 
 
1
  import gradio as gr
2
  import random as rd
3
+ from hugggingface_hub import InferenceClient
4
 
5
+ client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
6
+ def respond (message, history):
7
+ messages = [{"role": "system", "content": "You are a friendly chatbot."}]
8
+ if history:
9
+ messages.extend(history)
10
+ messages.append({"role": "user", "content": message})
11
+ response = client.chat_completion(
12
+ messages,
13
+ max_tokens=100
14
+
15
+ )
16
+ print(response['choices'][0]['message']['content'].strip())
17
+ return response['choices'][0]['message']['content'].strip()
18
+
19
+ def respond (message, history):
20
  eight_ball_answers = ["yes","no","ehhh probably not the best idea","Sure why not!","idk","i seems not","hahahaha... no","yes of course!"]
21
  random_choice = rd.choice(eight_ball_answers)
22
  return random_choice
23
 
24
+ chatbot = gr.ChatInterface(respond, type = "messages")
25
 
26
  chatbot.launch()
27