Spaces:
Sleeping
Sleeping
practiced for lesson 11 generative AI
Browse files
app.py
CHANGED
|
@@ -1,12 +1,30 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import random
|
|
|
|
| 3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
def random_message(message, history):
|
| 5 |
choices = ["yes.", "no.", "it is certain","without a doubt","outlook good","ask again later", "better not tell you now","very doubtful","don't count on it","my sources say no","outlook not so good","very doubtful","reply hazy, try again", "cannot predict now"]
|
| 6 |
chat_answer = random.choice(choices)
|
| 7 |
return chat_answer
|
| 8 |
|
| 9 |
print("Hello, World!")
|
| 10 |
-
chatbot = gr.ChatInterface(
|
| 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 |
+
|
| 9 |
+
messages = [{"role": "system", "content": "You are a friendly chatbot."}]
|
| 10 |
+
|
| 11 |
+
if history:
|
| 12 |
+
messages.extend(history)
|
| 13 |
+
|
| 14 |
+
messages.append({"role":"user", "content": message})
|
| 15 |
+
|
| 16 |
+
response = client.chat_completion(messages, max_tokens=100)
|
| 17 |
+
|
| 18 |
+
print(response['choices'][0]['message']['content'].strip())
|
| 19 |
+
|
| 20 |
+
return response['choices'][0]['message']['content'].strip()
|
| 21 |
+
|
| 22 |
def random_message(message, history):
|
| 23 |
choices = ["yes.", "no.", "it is certain","without a doubt","outlook good","ask again later", "better not tell you now","very doubtful","don't count on it","my sources say no","outlook not so good","very doubtful","reply hazy, try again", "cannot predict now"]
|
| 24 |
chat_answer = random.choice(choices)
|
| 25 |
return chat_answer
|
| 26 |
|
| 27 |
print("Hello, World!")
|
| 28 |
+
chatbot = gr.ChatInterface(respond, type = "messages")
|
| 29 |
|
| 30 |
chatbot.launch()
|