Update app.py
Browse files
app.py
CHANGED
|
@@ -1,12 +1,12 @@
|
|
| 1 |
-
|
| 2 |
-
import gradio as gr
|
| 3 |
import os
|
| 4 |
-
import
|
| 5 |
from gtts import gTTS
|
| 6 |
import tempfile
|
|
|
|
| 7 |
|
|
|
|
| 8 |
TOGETHER_API_KEY = os.getenv("TOGETHER_API_KEY")
|
| 9 |
-
|
| 10 |
|
| 11 |
def speak_text(text):
|
| 12 |
tts = gTTS(text)
|
|
@@ -21,24 +21,17 @@ def respond(message, history):
|
|
| 21 |
prompt += f"<|user|> {user_msg}\n<|assistant|> {bot_msg}\n"
|
| 22 |
prompt += f"<|user|> {message}\n<|assistant|>"
|
| 23 |
|
| 24 |
-
|
| 25 |
-
"
|
| 26 |
-
"
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
}
|
| 36 |
-
response = requests.post("https://api.together.xyz/inference", headers=headers, json=payload)
|
| 37 |
-
response_json = response.json()
|
| 38 |
-
output_text = response_json.get("output", "").strip().split("<|assistant|>")[-1].strip()
|
| 39 |
-
|
| 40 |
-
history.append((message, output_text))
|
| 41 |
-
audio_path = speak_text(output_text)
|
| 42 |
return history, history, audio_path
|
| 43 |
|
| 44 |
with gr.Blocks() as demo:
|
|
|
|
|
|
|
|
|
|
| 1 |
import os
|
| 2 |
+
import gradio as gr
|
| 3 |
from gtts import gTTS
|
| 4 |
import tempfile
|
| 5 |
+
from together import Together
|
| 6 |
|
| 7 |
+
# Load API key from Hugging Face Secrets
|
| 8 |
TOGETHER_API_KEY = os.getenv("TOGETHER_API_KEY")
|
| 9 |
+
client = Together(api_key=TOGETHER_API_KEY)
|
| 10 |
|
| 11 |
def speak_text(text):
|
| 12 |
tts = gTTS(text)
|
|
|
|
| 21 |
prompt += f"<|user|> {user_msg}\n<|assistant|> {bot_msg}\n"
|
| 22 |
prompt += f"<|user|> {message}\n<|assistant|>"
|
| 23 |
|
| 24 |
+
response = client.chat.completions.create(
|
| 25 |
+
model="meta-llama/Llama-3-8B-Instruct",
|
| 26 |
+
messages=[{"role": "user", "content": prompt}],
|
| 27 |
+
max_tokens=512,
|
| 28 |
+
temperature=0.7,
|
| 29 |
+
top_p=0.95
|
| 30 |
+
)
|
| 31 |
+
|
| 32 |
+
answer = response.choices[0].message.content.strip()
|
| 33 |
+
history.append((message, answer))
|
| 34 |
+
audio_path = speak_text(answer)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
return history, history, audio_path
|
| 36 |
|
| 37 |
with gr.Blocks() as demo:
|