LayaPrakash commited on
Commit
71c44b0
·
verified ·
1 Parent(s): 3c6b017

practice for lesson 11 generative AI

Browse files
Files changed (1) hide show
  1. app.py +14 -2
app.py CHANGED
@@ -1,12 +1,24 @@
1
  import gradio as gr
2
  import random
 
3
 
4
- def random_message(message, history):
 
 
 
 
 
 
 
 
 
 
 
5
  choices = ["yes", "no", "sure", "absolutely", "of course not", "by no means"]
6
  chat_answer = random.choice(choices)
7
  #use random to select ones of those choices
8
  return chat_answer
9
 
10
- chatbot = gr.ChatInterface(random_message, type = 'messages', title = "KWK Chatbot")
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
+ messages = [{"role": "system", "content": "You are a friendly chatbot."}]
9
+ if history:
10
+ messages.extend(history)
11
+ messages.append({"role" : "user", "content" : message})
12
+ response = client.chat_completion(messages, max_tokens = 100)
13
+ print(response["choices"][0]["message"]["content"].strip())
14
+ return response["choices"][0]["message"]["content"].strip()
15
+
16
+ def echo(message, history):
17
  choices = ["yes", "no", "sure", "absolutely", "of course not", "by no means"]
18
  chat_answer = random.choice(choices)
19
  #use random to select ones of those choices
20
  return chat_answer
21
 
22
+ chatbot = gr.ChatInterface(respond, type = 'messages')
23
 
24
  chatbot.launch()