import streamlit as st from utils import Recorder, record_audio, play_mp3 import os import requests import ast import json st.title("PinocchioLand!") # Display an image st.image( "https://i.pinimg.com/736x/30/e9/36/30e936e18912e9a5670b88ec94630b4a.jpg", use_column_width=True, ) 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())