practice for lesson 11 generative AI
Browse files
app.py
CHANGED
|
@@ -1,11 +1,29 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import random
|
|
|
|
| 3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
def echo(message, history):
|
| 5 |
my_list = ["absolutely", "ask again later", "things are murky", "it's a def yes", "perhaps", "it is decidedly so", "without a doubt", "outlook not so good", "signs point to yes", "signs point to no"]
|
| 6 |
return random.choice(my_list)
|
| 7 |
# gr.ChatInterface(echo, type = "messages")
|
| 8 |
-
|
|
|
|
| 9 |
|
| 10 |
|
| 11 |
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_tokens = 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 |
my_list = ["absolutely", "ask again later", "things are murky", "it's a def yes", "perhaps", "it is decidedly so", "without a doubt", "outlook not so good", "signs point to yes", "signs point to no"]
|
| 23 |
return random.choice(my_list)
|
| 24 |
# gr.ChatInterface(echo, type = "messages")
|
| 25 |
+
|
| 26 |
+
chatbot = gr.ChatInterface(respond, type="messages")
|
| 27 |
|
| 28 |
|
| 29 |
chatbot.launch()
|