Spaces:
Sleeping
Sleeping
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 random_message(message, history):
|
| 5 |
choices = ["Mhm", "nah fam", "I don't like your tone, buddy rewrite that.", "Uhm, sure, ig.", "What a good question! So-", "I know what you are.", "I'm uncomfortable with the energy we've created today.", "I like that question! Ask someone else."]
|
| 6 |
random_choice = random.choice(choices)
|
| 7 |
return random_choice
|
| 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 |
+
|
| 15 |
+
response = client.chat_completion(messages, max_tokens = 100)
|
| 16 |
+
|
| 17 |
+
print(response["choices"][0]["message"]["content"].strip())
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
return response["choices"][0]["message"]["content"].strip()
|
| 21 |
+
|
| 22 |
def random_message(message, history):
|
| 23 |
choices = ["Mhm", "nah fam", "I don't like your tone, buddy rewrite that.", "Uhm, sure, ig.", "What a good question! So-", "I know what you are.", "I'm uncomfortable with the energy we've created today.", "I like that question! Ask someone else."]
|
| 24 |
random_choice = random.choice(choices)
|
| 25 |
return random_choice
|
| 26 |
|
| 27 |
+
chatbot = gr.ChatInterface(respond, type = "messages", description = "<strong><center>Don't talk to me please.</strong><br>go away.", title = "I'm not a chatbot")
|
| 28 |
|
| 29 |
chatbot.launch()
|