Spaces:
Runtime error
Runtime error
Commit
·
09be2b6
1
Parent(s):
b6426be
Initial commit
Browse files
app.py
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import subprocess
|
| 3 |
+
import tempfile
|
| 4 |
+
import sys
|
| 5 |
+
import os
|
| 6 |
+
from os.path import exists
|
| 7 |
+
import requests
|
| 8 |
+
import tarfile
|
| 9 |
+
|
| 10 |
+
BASE_PATH = os.getcwd() # /home/user/app
|
| 11 |
+
URL_PIPER_DOWNLOAD = "https://github.com/rhasspy/piper/releases/download/v1.2.0/piper_amd64.tar.gz"
|
| 12 |
+
URL_TV_HESSISCH_ONNX = "https://huggingface.co/Thorsten-Voice/Hessisch/resolve/main/Thorsten-Voice_Hessisch_Piper_high-Sep2023.onnx"
|
| 13 |
+
URL_TV_HESSISCH_JSON = "https://huggingface.co/Thorsten-Voice/Hessisch/raw/main/Thorsten-Voice_Hessisch_Piper_high-Sep2023.onnx.json"
|
| 14 |
+
TV_HESSISCH_FILENAME = "Thorsten-Voice_Hessisch_Piper_high-Sep2023"
|
| 15 |
+
FOLDER_TV_HESSISCH_MODEL = os.path.join(BASE_PATH, "Model")
|
| 16 |
+
TMP_PIPER_FILENAME = os.path.join(BASE_PATH, "piper.tgz")
|
| 17 |
+
|
| 18 |
+
##########################
|
| 19 |
+
# CHECK OR INSTALL PIPER #
|
| 20 |
+
##########################
|
| 21 |
+
if os.path.exists(os.path.join(BASE_PATH,"piper")) == False:
|
| 22 |
+
|
| 23 |
+
# Piper not downloaded and extracted yet, let's do this first.
|
| 24 |
+
response = requests.get(URL_PIPER_DOWNLOAD)
|
| 25 |
+
|
| 26 |
+
if response.status_code == 200:
|
| 27 |
+
with open(TMP_PIPER_FILENAME, 'wb') as f:
|
| 28 |
+
f.write(response.content)
|
| 29 |
+
|
| 30 |
+
with tarfile.open(TMP_PIPER_FILENAME, 'r:gz') as tar:
|
| 31 |
+
tar.extractall(BASE_PATH)
|
| 32 |
+
|
| 33 |
+
else:
|
| 34 |
+
st.markdown(f"Failed to download Piper TTS from {URL_PIPER_DOWNLOAD} (Status code: {response.status_code})")
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
###################################################################
|
| 38 |
+
# CHECK OR DOWNLOAD Thorsten-Voice HESSISCH PIPER TTS MODEL FILES #
|
| 39 |
+
###################################################################
|
| 40 |
+
if os.path.exists(os.path.join(FOLDER_TV_HESSISCH_MODEL,TV_HESSISCH_FILENAME + '.onnx')) == False:
|
| 41 |
+
if not os.path.exists(FOLDER_TV_HESSISCH_MODEL):
|
| 42 |
+
os.makedirs(FOLDER_TV_HESSISCH_MODEL)
|
| 43 |
+
|
| 44 |
+
# Download Model (ONNX-file) #
|
| 45 |
+
##############################
|
| 46 |
+
response = requests.get(URL_TV_HESSISCH_ONNX)
|
| 47 |
+
|
| 48 |
+
if response.status_code == 200:
|
| 49 |
+
with open(os.path.join(FOLDER_TV_HESSISCH_MODEL,TV_HESSISCH_FILENAME + '.onnx'), 'wb') as f:
|
| 50 |
+
f.write(response.content)
|
| 51 |
+
else:
|
| 52 |
+
st.markdown(f"Failed to download model file {TV_HESSISCH_FILENAME} (Status code: {response.status_code})")
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
# Download Model (JSON-file) #
|
| 56 |
+
##############################
|
| 57 |
+
response = requests.get(URL_TV_HESSISCH_JSON)
|
| 58 |
+
|
| 59 |
+
if response.status_code == 200:
|
| 60 |
+
with open(os.path.join(FOLDER_TV_HESSISCH_MODEL,TV_HESSISCH_FILENAME + '.onnx.json'), 'wb') as f:
|
| 61 |
+
f.write(response.content)
|
| 62 |
+
else:
|
| 63 |
+
st.markdown(f"Failed to download model CONFIG JSON file {TV_HESSISCH_FILENAME} (Status code: {response.status_code})")
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
image = Image.open('Thorsten-Voice_transparent.png')
|
| 67 |
+
st.image(image)
|
| 68 |
+
|
| 69 |
+
st.title('Thorsten-Voice babbelt jetzt ach uff (Süd)Hessisch!')
|
| 70 |
+
st.header('Guude!')
|
| 71 |
+
st.markdown('Hier kannste mei deutsche, freie un künstliche Thorsten-Voice TTS-Stimm ([mehr Details zum Projekt](https://www.Thorsten-Voice.de)) ach uff Hessisch babbele lasse.')
|
| 72 |
+
|
| 73 |
+
st.markdown('__Un wie immer bei Thorsten-Voice TTS-Stimme gilt:__')
|
| 74 |
+
st.markdown("* Kost nix (*Kostenfrei in der Nutzung*)")
|
| 75 |
+
st.markdown("* Funktioniert ach uff deim lokale Compjuter ohne Klaud (*Kann ohne Internetzugang erzeugt werden*)")
|
| 76 |
+
st.markdown("* Is Lizenzrechtlich in de Nutzung ned ingeschränkt (*Darf jeder verwenden*)")
|
| 77 |
+
|
| 78 |
+
with st.form("my_form"):
|
| 79 |
+
text = st.text_area("Ei, was soll ich dann babbele?",max_chars=250)
|
| 80 |
+
|
| 81 |
+
submitted = st.form_submit_button("Schwätz los!")
|
| 82 |
+
|
| 83 |
+
if submitted:
|
| 84 |
+
filename = tempfile.NamedTemporaryFile(suffix=".wav", delete=False)
|
| 85 |
+
|
| 86 |
+
cmd = "echo '" + text + "' | /home/user/app/piper/piper --model '" + os.path.join(FOLDER_TV_HESSISCH_MODEL, TV_HESSISCH_FILENAME) + ".onnx' --output_file " + filename.name
|
| 87 |
+
result = subprocess.run(cmd, shell=True)
|
| 88 |
+
audio_file = open(filename.name, 'rb')
|
| 89 |
+
audio_bytes = audio_file.read()
|
| 90 |
+
st.audio(audio_bytes,format="audio/wav")
|
| 91 |
+
|
| 92 |
+
st.header('Willste misch unnerstütze?')
|
| 93 |
+
st.markdown('Man soll seine Wünsche und Ziele ja auch kommuizieren, damit sie in Erfüllung gehen 🤗.')
|
| 94 |
+
st.markdown('Also, los gehts. Ich hätte gerne **den silbernen Youtube Playbutton für 100.000 Abonnenten**. ' +
|
| 95 |
+
'Ich weiß nicht, ob ich dieses Ziel jemals erreichen kann, aber wenn du mich unterstützen möchtest,' +
|
| 96 |
+
'dann ist ein Abo auf meinem [**"Thorsten-Voice" Youtube Kanal**](https://www.youtube.com/c/ThorstenMueller?sub_confirmation=1) gerne gesehen')
|
| 97 |
+
st.markdown('Abgesehen davon freue ich mich natürlich über Rückmeldungen und/oder Verbesserungsvorschläge')
|
| 98 |
+
|
| 99 |
+
image = Image.open('Ziel_Thorsten-Voice_Playbutton.png')
|
| 100 |
+
st.image(image,caption='Fotomontage vom silbernen Youtube Playbutton für Thorsten-Voice Kanal. Bildquelle: Wikipedia')
|
| 101 |
+
|
| 102 |
+
st.markdown('🇺🇸 Thanks for [Michael Hansen](https://github.com/synesthesiam) for providing [Piper TTS](https://github.com/rhasspy/piper) on which this "hessische" Thorsten-Voice model relies 😊')
|