Spaces:
Sleeping
Sleeping
import streamlit as st | |
import requests | |
from utils import Recorder, record_audio, play_mp3 | |
import json | |
st.title("Audio Pipeline") | |
button_label = "record" | |
if st.button(button_label): | |
st.write("recording...") | |
recording_path = record_audio() | |
button_label | |
with open(recording_path, "rb") as audio_file: | |
# Define the multipart/form-data payload | |
files = {"audio_file": (recording_path.split("/")[-1], audio_file, "audio/mp3")} | |
# Make the POST request | |
stt_response = requests.post("http://localhost:8000/stt_query/", files=files) | |
st.write("domanda :", stt_response.json()) | |
# LLM | |
url = "http://localhost:8000/llm_query/" | |
# Append the query parameter to the URL | |
llm_response = requests.post( | |
url=url, params={"llm_query": str(stt_response.content)} | |
) | |
data = llm_response.json() | |
inner_data = json.loads(data["response_text"]) | |
# Now, you can access the data from the inner JSON | |
risposta = inner_data.get("risposta") | |
stato = inner_data.get("stato") | |
tipologia = inner_data.get("tipologia") | |
print(risposta) | |
st.write("risposta: ", risposta) | |
st.write("stato: ", stato) | |
st.write("tipologia: ", tipologia) | |
# TTS | |
url = "http://localhost:8000/tts_query/" | |
out_path = requests.post(url=url, params={"input_text": str(risposta)}) | |
print(out_path.json()) | |
play_mp3(out_path.json()) | |