Update app.py
Browse files
app.py
CHANGED
@@ -19,7 +19,8 @@ BASE_PATH_MODEL = os.path.join(BASE_PATH, "Model")
|
|
19 |
URL_PIPER_DOWNLOAD = "https://github.com/rhasspy/piper/releases/download/v1.2.0/piper_amd64.tar.gz"
|
20 |
|
21 |
# TTS model files
|
22 |
-
URL_TTS_ONNX = "https://huggingface.co/
|
|
|
23 |
TMP_PIPER_FILENAME = os.path.join(BASE_PATH, "piper.tgz")
|
24 |
|
25 |
headers = {"Authorization": f"Bearer {HF_TOKEN}"}
|
@@ -67,6 +68,21 @@ if os.path.exists(BASE_PATH_MODEL) == False:
|
|
67 |
else:
|
68 |
st.markdown(f"Failed to download TTS json from {URL_TTS_ONNX}.json (Status code: {response.status_code})")
|
69 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
70 |
|
71 |
###########################
|
72 |
# MODEL DOWNLOAD FINISHED #
|
@@ -93,7 +109,8 @@ st.header('A text-to-speech (TTS) model in Azerbaijani language')
|
|
93 |
with st.form("my_form"):
|
94 |
option = st.selectbox(
|
95 |
'Choose the model.',
|
96 |
-
['Model 1']
|
|
|
97 |
|
98 |
text = st.text_area("Text to generate audio from:",max_chars=500)
|
99 |
submitted = st.form_submit_button("Submit")
|
@@ -105,11 +122,12 @@ with st.form("my_form"):
|
|
105 |
# Set Piper TTS command based on choice
|
106 |
PIPER_CMD = os.path.join(BASE_PATH,"piper","piper")
|
107 |
SPEAKER_ID = "0"
|
108 |
-
MODEL = "last.onnx"
|
109 |
|
110 |
match option:
|
111 |
case "Model 1":
|
112 |
MODEL = "last.onnx"
|
|
|
|
|
113 |
|
114 |
cmd = "echo '" + text + "' | " + BASE_PATH + "/piper/piper --model " + os.path.join(BASE_PATH_MODEL, MODEL) + " --speaker " + SPEAKER_ID + " --output_file " + filename.name
|
115 |
|
|
|
19 |
URL_PIPER_DOWNLOAD = "https://github.com/rhasspy/piper/releases/download/v1.2.0/piper_amd64.tar.gz"
|
20 |
|
21 |
# TTS model files
|
22 |
+
URL_TTS_ONNX = "https://huggingface.co/CavidanZ/TTS-azerbaijani-model/resolve/main/last.onnx"
|
23 |
+
URL_TTS_ONNX_2 = "https://huggingface.co/CavidanZ/TTS-azerbaijani-model/resolve/main/last2.onnx"
|
24 |
TMP_PIPER_FILENAME = os.path.join(BASE_PATH, "piper.tgz")
|
25 |
|
26 |
headers = {"Authorization": f"Bearer {HF_TOKEN}"}
|
|
|
68 |
else:
|
69 |
st.markdown(f"Failed to download TTS json from {URL_TTS_ONNX}.json (Status code: {response.status_code})")
|
70 |
|
71 |
+
response = requests.get(URL_TTS_ONNX_2, headers=headers)
|
72 |
+
if response.status_code == 200:
|
73 |
+
with open(os.path.join(BASE_PATH_MODEL, "last2.onnx"), 'wb') as f:
|
74 |
+
f.write(response.content)
|
75 |
+
else:
|
76 |
+
st.markdown(f"Failed to download TTS from {URL_TTS_ONNX} (Status code: {response.status_code})")
|
77 |
+
|
78 |
+
|
79 |
+
response = requests.get((URL_TTS_ONNX_2 + ".json"), headers=headers)
|
80 |
+
if response.status_code == 200:
|
81 |
+
with open(os.path.join(BASE_PATH_MODEL, "last2.onnx.json"), 'wb') as f:
|
82 |
+
f.write(response.content)
|
83 |
+
else:
|
84 |
+
st.markdown(f"Failed to download TTS json from {URL_TTS_ONNX}.json (Status code: {response.status_code})")
|
85 |
+
|
86 |
|
87 |
###########################
|
88 |
# MODEL DOWNLOAD FINISHED #
|
|
|
109 |
with st.form("my_form"):
|
110 |
option = st.selectbox(
|
111 |
'Choose the model.',
|
112 |
+
['Model 1'],
|
113 |
+
['Model 2'])
|
114 |
|
115 |
text = st.text_area("Text to generate audio from:",max_chars=500)
|
116 |
submitted = st.form_submit_button("Submit")
|
|
|
122 |
# Set Piper TTS command based on choice
|
123 |
PIPER_CMD = os.path.join(BASE_PATH,"piper","piper")
|
124 |
SPEAKER_ID = "0"
|
|
|
125 |
|
126 |
match option:
|
127 |
case "Model 1":
|
128 |
MODEL = "last.onnx"
|
129 |
+
case "Model 2":
|
130 |
+
MODEL = "last2.onnx"
|
131 |
|
132 |
cmd = "echo '" + text + "' | " + BASE_PATH + "/piper/piper --model " + os.path.join(BASE_PATH_MODEL, MODEL) + " --speaker " + SPEAKER_ID + " --output_file " + filename.name
|
133 |
|