JordiFFJ commited on
Commit
fceee68
·
verified ·
1 Parent(s): 2f004a2

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +57 -0
app.py ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import requests
3
+
4
+ API_URL_FASTSPEECH2 = "https://api-inference.huggingface.co/models/facebook/fastspeech2-en-ljspeech"
5
+ API_URL_DISTIL_WHISPER = "https://api-inference.huggingface.co/models/distil-whisper/distil-large-v3"
6
+ API_URL_WAV2VEC2 = "https://api-inference.huggingface.co/models/facebook/wav2vec2-large-960h"
7
+
8
+ def query(api_url, payload):
9
+ response = requests.post(api_url, json=payload)
10
+ if response.status_code == 200:
11
+ return response.content
12
+ else:
13
+ st.error(f"Erreur {response.status_code}: {response.text}")
14
+ return None
15
+
16
+ def query_audio(api_url, audio_file):
17
+ response = requests.post(api_url, files={"file": audio_file})
18
+ if response.status_code == 200:
19
+ return response.json()
20
+ else:
21
+ st.error(f"Erreur {response.status_code}: {response.text}")
22
+ return None
23
+
24
+ def main():
25
+
26
+ st.title("Text to speech App")
27
+ # Sidebar pour la navigation entre les modèles
28
+ st.sidebar.image("img/istockphoto-1391947389-612x612.jpg")
29
+ model_selection = st.sidebar.selectbox("Sélectionnez le modèle", ["Text-to-Speech (fastspeech2-en-ljspeech)", "Speech-to-Text (distil-whisper/distil-large-v3)"])
30
+
31
+ if model_selection == "Text-to-Speech (fastspeech2-en-ljspeech)":
32
+ st.subheader("Text-to-Speech (fastspeech2-en-ljspeech)")
33
+ st.image("img/image2.png")
34
+ st.text("le modele prend environ 20s pou se charger veiller patienter quelques secondes")
35
+ user_input_tts = st.text_area("Entrez le texte que vous souhaitez convertir en audio:")
36
+
37
+ if st.button("Convertir le texte en audio avec fastspeech2-en-ljspeech"):
38
+ payload_tts = {"inputs": user_input_tts}
39
+ audio_bytes = query(API_URL_FASTSPEECH2, payload_tts)
40
+
41
+ if audio_bytes:
42
+ st.audio(audio_bytes, format="audio/wav", start_time=0)
43
+
44
+ elif model_selection == "Speech-to-Text (distil-whisper/distil-large-v3)":
45
+ st.subheader("Speech-to-Text (distil-whisper/distil-large-v3)")
46
+ st.image("img/istockphoto-1391947389-612x612.jpg")
47
+ audio_file = st.file_uploader("Téléchargez votre fichier audio", type=["wav", "mp3", "flac"])
48
+
49
+ if st.button("Convertir l'audio en texte avec distil-whisper/distil-large-v3") and audio_file is not None:
50
+ result_stt = query_audio(API_URL_DISTIL_WHISPER, audio_file)
51
+
52
+ if result_stt:
53
+ st.subheader("Texte transcrit:")
54
+ st.write(result_stt.get("text", "Aucune transcription trouvée."))
55
+
56
+ if __name__ == "__main__":
57
+ main()