Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,5 +1,29 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
with gr.Blocks() as block:
|
| 4 |
gr.HTML(
|
| 5 |
f"""
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
|
| 3 |
+
from huggingface_hub import InferenceClient
|
| 4 |
+
|
| 5 |
+
client = InferenceClient(token=os.getenv("HF_TOKEN"))
|
| 6 |
+
|
| 7 |
+
def generate_response(audio):
|
| 8 |
+
gr.Info("Transcribing Audio", duration=5)
|
| 9 |
+
question = client.automatic_speech_recognition(audio).text
|
| 10 |
+
|
| 11 |
+
messages = [{"role": "system", "content": ("You are a magic 8 ball."
|
| 12 |
+
"Someone will present to you a situation or question and your job "
|
| 13 |
+
"is to answer with a cryptic adage or proverb such as "
|
| 14 |
+
"'curiosity killed the cat' or 'The early bird gets the worm'."
|
| 15 |
+
"Keep your answers short and do not include the phrase 'Magic 8 Ball' in your response. If the question does not make sense or is off-topic, say 'Foolish questions get foolish answers.'"
|
| 16 |
+
"For example, 'Magic 8 Ball, should I get a dog?', 'A dog is ready for you but are you ready for the dog?'")},
|
| 17 |
+
{"role": "user", "content": f"Magic 8 Ball please answer this question - {question}"}]
|
| 18 |
+
|
| 19 |
+
response = client.chat_completion(messages, max_tokens=64, seed=random.randint(1, 5000),
|
| 20 |
+
model="mistralai/Mistral-7B-Instruct-v0.3")
|
| 21 |
+
|
| 22 |
+
response = response.choices[0].message.content.replace("Magic 8 Ball", "").replace(":", "")
|
| 23 |
+
return response, None, None
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
|
| 27 |
with gr.Blocks() as block:
|
| 28 |
gr.HTML(
|
| 29 |
f"""
|