JordiFFJ's picture
Update app.py
4a4db02 verified
import streamlit as st
import requests
API_URL_FASTSPEECH2 = "https://api-inference.huggingface.co/models/facebook/fastspeech2-en-ljspeech"
API_URL_DISTIL_WHISPER = "https://api-inference.huggingface.co/models/distil-whisper/distil-large-v3"
API_URL_WAV2VEC2 = "https://api-inference.huggingface.co/models/facebook/wav2vec2-large-960h"
def query(api_url, payload):
response = requests.post(api_url, json=payload)
if response.status_code == 200:
return response.content
else:
st.error(f"Erreur {response.status_code}: {response.text}")
return None
def query_audio(api_url, audio_file):
response = requests.post(api_url, files={"file": audio_file})
if response.status_code == 200:
return response.json()
else:
st.error(f"Erreur {response.status_code}: {response.text}")
return None
def main():
st.title("Text to speech App")
# Sidebar pour la navigation entre les modèles
st.sidebar.image("istockphoto-1391947389-612x612.jpg")
model_selection = st.sidebar.selectbox("Sélectionnez le modèle", ["Text-to-Speech (fastspeech2-en-ljspeech)", "Speech-to-Text (distil-whisper/distil-large-v3)"])
if model_selection == "Text-to-Speech (fastspeech2-en-ljspeech)":
st.subheader("Text-to-Speech (fastspeech2-en-ljspeech)")
st.image("image2.png")
st.text("le modele prend environ 20s pou se charger veiller patienter quelques secondes")
user_input_tts = st.text_area("Entrez le texte que vous souhaitez convertir en audio:")
if st.button("Convertir le texte en audio avec fastspeech2-en-ljspeech"):
payload_tts = {"inputs": user_input_tts}
audio_bytes = query(API_URL_FASTSPEECH2, payload_tts)
if audio_bytes:
st.audio(audio_bytes, format="audio/wav", start_time=0)
elif model_selection == "Speech-to-Text (distil-whisper/distil-large-v3)":
st.subheader("Speech-to-Text (distil-whisper/distil-large-v3)")
st.image("istockphoto-1391947389-612x612.jpg")
audio_file = st.file_uploader("Téléchargez votre fichier audio", type=["wav", "mp3", "flac"])
if st.button("Convertir l'audio en texte avec distil-whisper/distil-large-v3") and audio_file is not None:
result_stt = query_audio(API_URL_DISTIL_WHISPER, audio_file)
if result_stt:
st.subheader("Texte transcrit:")
st.write(result_stt.get("text", "Aucune transcription trouvée."))
if __name__ == "__main__":
main()