Hessisch / app.py
Thorsten-Voice's picture
Add dependency for image visu
ca52792
raw
history blame
No virus
4.94 kB
import streamlit as st
import subprocess
import tempfile
import sys
import os
from os.path import exists
import requests
import tarfile
from PIL import Image
BASE_PATH = os.getcwd() # /home/user/app
URL_PIPER_DOWNLOAD = "https://github.com/rhasspy/piper/releases/download/v1.2.0/piper_amd64.tar.gz"
URL_TV_HESSISCH_ONNX = "https://huggingface.co./Thorsten-Voice/Hessisch/resolve/main/Thorsten-Voice_Hessisch_Piper_high-Sep2023.onnx"
URL_TV_HESSISCH_JSON = "https://huggingface.co./Thorsten-Voice/Hessisch/raw/main/Thorsten-Voice_Hessisch_Piper_high-Sep2023.onnx.json"
TV_HESSISCH_FILENAME = "Thorsten-Voice_Hessisch_Piper_high-Sep2023"
FOLDER_TV_HESSISCH_MODEL = os.path.join(BASE_PATH, "Model")
TMP_PIPER_FILENAME = os.path.join(BASE_PATH, "piper.tgz")
##########################
# CHECK OR INSTALL PIPER #
##########################
if os.path.exists(os.path.join(BASE_PATH,"piper")) == False:
# Piper not downloaded and extracted yet, let's do this first.
response = requests.get(URL_PIPER_DOWNLOAD)
if response.status_code == 200:
with open(TMP_PIPER_FILENAME, 'wb') as f:
f.write(response.content)
with tarfile.open(TMP_PIPER_FILENAME, 'r:gz') as tar:
tar.extractall(BASE_PATH)
else:
st.markdown(f"Failed to download Piper TTS from {URL_PIPER_DOWNLOAD} (Status code: {response.status_code})")
###################################################################
# CHECK OR DOWNLOAD Thorsten-Voice HESSISCH PIPER TTS MODEL FILES #
###################################################################
if os.path.exists(os.path.join(FOLDER_TV_HESSISCH_MODEL,TV_HESSISCH_FILENAME + '.onnx')) == False:
if not os.path.exists(FOLDER_TV_HESSISCH_MODEL):
os.makedirs(FOLDER_TV_HESSISCH_MODEL)
# Download Model (ONNX-file) #
##############################
response = requests.get(URL_TV_HESSISCH_ONNX)
if response.status_code == 200:
with open(os.path.join(FOLDER_TV_HESSISCH_MODEL,TV_HESSISCH_FILENAME + '.onnx'), 'wb') as f:
f.write(response.content)
else:
st.markdown(f"Failed to download model file {TV_HESSISCH_FILENAME} (Status code: {response.status_code})")
# Download Model (JSON-file) #
##############################
response = requests.get(URL_TV_HESSISCH_JSON)
if response.status_code == 200:
with open(os.path.join(FOLDER_TV_HESSISCH_MODEL,TV_HESSISCH_FILENAME + '.onnx.json'), 'wb') as f:
f.write(response.content)
else:
st.markdown(f"Failed to download model CONFIG JSON file {TV_HESSISCH_FILENAME} (Status code: {response.status_code})")
image = Image.open('Thorsten-Voice_transparent.png')
st.image(image)
st.title('Thorsten-Voice babbelt jetzt ach uff (Süd)Hessisch!')
st.header('Guude!')
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.')
st.markdown('__Un wie immer bei Thorsten-Voice TTS-Stimme gilt:__')
st.markdown("* Kost nix (*Kostenfrei in der Nutzung*)")
st.markdown("* Funktioniert ach uff deim lokale Compjuter ohne Klaud (*Kann ohne Internetzugang erzeugt werden*)")
st.markdown("* Is Lizenzrechtlich in de Nutzung ned ingeschränkt (*Darf jeder verwenden*)")
with st.form("my_form"):
text = st.text_area("Ei, was soll ich dann babbele?",max_chars=250)
submitted = st.form_submit_button("Schwätz los!")
if submitted:
filename = tempfile.NamedTemporaryFile(suffix=".wav", delete=False)
cmd = "echo '" + text + "' | /home/user/app/piper/piper --model '" + os.path.join(FOLDER_TV_HESSISCH_MODEL, TV_HESSISCH_FILENAME) + ".onnx' --output_file " + filename.name
result = subprocess.run(cmd, shell=True)
audio_file = open(filename.name, 'rb')
audio_bytes = audio_file.read()
st.audio(audio_bytes,format="audio/wav")
st.header('Willste misch unnerstütze?')
st.markdown('Man soll seine Wünsche und Ziele ja auch kommuizieren, damit sie in Erfüllung gehen 🤗.')
st.markdown('Also, los gehts. Ich hätte gerne **den silbernen Youtube Playbutton für 100.000 Abonnenten**. ' +
'Ich weiß nicht, ob ich dieses Ziel jemals erreichen kann, aber wenn du mich unterstützen möchtest,' +
'dann ist ein Abo auf meinem [**"Thorsten-Voice" Youtube Kanal**](https://www.youtube.com/c/ThorstenMueller?sub_confirmation=1) gerne gesehen')
st.markdown('Abgesehen davon freue ich mich natürlich über Rückmeldungen und/oder Verbesserungsvorschläge')
image = Image.open('Ziel_Thorsten-Voice_Playbutton.png')
st.image(image,caption='Fotomontage vom silbernen Youtube Playbutton für Thorsten-Voice Kanal. Bildquelle: Wikipedia')
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 😊')