Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,9 +1,33 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import random
|
|
|
|
|
|
|
| 3 |
# import lines go at the top! Any libraries I need to import go up here ^^
|
| 4 |
|
| 5 |
-
|
| 6 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
# def yes_or_no(message, history):
|
| 9 |
# return random.choice(['Yes', 'No'])
|
|
@@ -13,9 +37,9 @@ def magic_8_ball(message,history):
|
|
| 13 |
|
| 14 |
print("Hello World!")
|
| 15 |
chatbot = gr.ChatInterface(
|
| 16 |
-
|
| 17 |
-
title="The Psychic Magic 8 Ball!",
|
| 18 |
-
description="Ask any yes or no question to learn your future",
|
| 19 |
type="messages"
|
| 20 |
)
|
| 21 |
# defining my chatbot so that the user can interact, see their conversation history and send new messages
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import random
|
| 3 |
+
from huggingface_hub import InferenceClient
|
| 4 |
+
# IMPORT INFERENCE CLIENT
|
| 5 |
# import lines go at the top! Any libraries I need to import go up here ^^
|
| 6 |
|
| 7 |
+
client = InferenceClient("microsoft/phi-4")
|
| 8 |
+
# CREATE AN INSTANCE OF INFERENCE CLIENT THAT'S CONNECTED TO THE MICROSOFT PHI GENERATION MODEL
|
| 9 |
+
|
| 10 |
+
def respond(message, history):
|
| 11 |
+
|
| 12 |
+
messages = [{"role": "system", "content": "You are a friendly chatbot."}]
|
| 13 |
+
|
| 14 |
+
if history:
|
| 15 |
+
messages.extend(history)
|
| 16 |
+
|
| 17 |
+
messages.append({"role": "user", "content": message})
|
| 18 |
+
|
| 19 |
+
response = client.chat_completion(
|
| 20 |
+
messages,
|
| 21 |
+
max_tokens=100
|
| 22 |
+
)
|
| 23 |
+
|
| 24 |
+
return response['choices'][0]['message']['content'].strip()
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
# CODE NEW RESPOND FUNCTION
|
| 28 |
+
|
| 29 |
+
#def magic_8_ball(message,history):
|
| 30 |
+
# return random.choice(['Maybe', "I don't think so honey", "Yea right", "Absolutely!", "I can see that for you.", "ijbol"])
|
| 31 |
|
| 32 |
# def yes_or_no(message, history):
|
| 33 |
# return random.choice(['Yes', 'No'])
|
|
|
|
| 37 |
|
| 38 |
print("Hello World!")
|
| 39 |
chatbot = gr.ChatInterface(
|
| 40 |
+
respond, # CHANGE THE FUNCTION MY CHATBOT RUNS
|
| 41 |
+
#title="The Psychic Magic 8 Ball!",
|
| 42 |
+
#description="Ask any yes or no question to learn your future",
|
| 43 |
type="messages"
|
| 44 |
)
|
| 45 |
# defining my chatbot so that the user can interact, see their conversation history and send new messages
|