Spaces:
Sleeping
Sleeping
practice for lesson 11 generative ai
Browse files
app.py
CHANGED
|
@@ -1,11 +1,28 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import random
|
|
|
|
| 3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
def echo(message, history):
|
| 5 |
choices = ["yes", "no", "better not tell you now", "without a doubt", "very doubtful", "cannot predict now", "you may rely on it", "don't count on it", "reply hazy, try again"]
|
| 6 |
new = random.choice(choices)
|
| 7 |
return new
|
| 8 |
|
| 9 |
-
chatbot = gr.ChatInterface(
|
| 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 |
+
response = client.chat_completion(
|
| 15 |
+
messages,
|
| 16 |
+
max_tokens=100
|
| 17 |
+
)
|
| 18 |
+
print(response['choices'][0]['message']['content'].strip())
|
| 19 |
+
return response['choices'][0]['message']['content'].strip()
|
| 20 |
+
|
| 21 |
def echo(message, history):
|
| 22 |
choices = ["yes", "no", "better not tell you now", "without a doubt", "very doubtful", "cannot predict now", "you may rely on it", "don't count on it", "reply hazy, try again"]
|
| 23 |
new = random.choice(choices)
|
| 24 |
return new
|
| 25 |
|
| 26 |
+
chatbot = gr.ChatInterface(respond, type = "messages", title = "Chatbot")
|
| 27 |
|
| 28 |
chatbot.launch()
|