Spaces:
Sleeping
Sleeping
seawolf2357
commited on
Commit
β’
5888805
1
Parent(s):
a43c03b
Update app.py
Browse files
app.py
CHANGED
@@ -2,7 +2,6 @@ import streamlit as st
|
|
2 |
import requests
|
3 |
import streamlit.components.v1 as components
|
4 |
from gtts import gTTS
|
5 |
-
import os
|
6 |
from io import BytesIO
|
7 |
|
8 |
# νμ΄μ§ μ€μ
|
@@ -27,22 +26,39 @@ if 'current_menu' not in st.session_state:
|
|
27 |
if 'current_sub_menu' not in st.session_state:
|
28 |
st.session_state['current_sub_menu'] = ''
|
29 |
|
30 |
-
# λ©μΈ λ©λ΄ μ ν
|
31 |
selected_menu = st.sidebar.selectbox("Menu", list(menus.keys()), key='main_menu')
|
32 |
st.session_state['current_menu'] = selected_menu
|
33 |
|
34 |
# νμ λ©λ΄ μ ν (ν΄λΉλλ κ²½μ°)
|
35 |
if selected_menu in menus:
|
36 |
-
# `key` μΈμμ `selected_menu` κ°μ μ¬μ©νμ¬ κ³ μ ν ν€λ₯Ό μμ±
|
37 |
selected_sub_menu = st.sidebar.selectbox("Sub Menu", [""] + menus[selected_menu], key=f'sub_menu_{selected_menu}')
|
38 |
st.session_state['current_sub_menu'] = selected_sub_menu
|
39 |
else:
|
40 |
st.session_state['current_sub_menu'] = ''
|
41 |
|
42 |
-
|
43 |
-
|
44 |
-
|
|
|
|
|
|
|
|
|
45 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
46 |
# Pexels API ν€ μ€μ
|
47 |
PEXELS_API_KEY = "5woz23MGx1QrSY0WHFb0BRi29JvbXPu97Hg0xnklYgHUI8G0w23FKH62"
|
48 |
|
@@ -95,29 +111,6 @@ if selected_menu == "Image" and st.session_state['current_sub_menu'] == "Remove
|
|
95 |
components.iframe("https://seawolf2357-gttstest.hf.space", width=None, height=600, scrolling=True)
|
96 |
|
97 |
|
98 |
-
# 'Sound' λ©λ΄μ 'TTS(Voice)' μ ν μ
|
99 |
-
if st.sidebar.selectbox("Menu", list(menus.keys())) == "Sound":
|
100 |
-
if st.sidebar.selectbox("Sub Menu", menus["Sound"]) == "TTS(Voice)":
|
101 |
-
st.header("Text-to-Speech")
|
102 |
-
# ν
μ€νΈ μ
λ ₯
|
103 |
-
text = st.text_area("Enter text to synthesize", "Hello, welcome to ViDraft TTS service.")
|
104 |
-
# μΈμ΄ μ ν
|
105 |
-
language = st.selectbox("Choose Language", ["en", "es", "de", "fr", "it", "pt", "ru", "ja", "ko", "zh-cn", "zh-tw"])
|
106 |
-
|
107 |
-
# 'Synthesize' λ²νΌ
|
108 |
-
if st.button("Synthesize"):
|
109 |
-
if text:
|
110 |
-
try:
|
111 |
-
tts = gTTS(text=text, lang=language, slow=False)
|
112 |
-
audio_file = BytesIO()
|
113 |
-
tts.write_to_fp(audio_file)
|
114 |
-
audio_file.seek(0)
|
115 |
-
st.audio(audio_file, format='audio/mp3')
|
116 |
-
except Exception as e:
|
117 |
-
st.error(f"Error: {e}")
|
118 |
-
else:
|
119 |
-
st.warning("Please enter some text to synthesize.")
|
120 |
-
|
121 |
|
122 |
# 'Home' νμ΄μ§ νμ
|
123 |
if selected_menu == "Home":
|
|
|
2 |
import requests
|
3 |
import streamlit.components.v1 as components
|
4 |
from gtts import gTTS
|
|
|
5 |
from io import BytesIO
|
6 |
|
7 |
# νμ΄μ§ μ€μ
|
|
|
26 |
if 'current_sub_menu' not in st.session_state:
|
27 |
st.session_state['current_sub_menu'] = ''
|
28 |
|
29 |
+
# λ©μΈ λ©λ΄ μ ν
|
30 |
selected_menu = st.sidebar.selectbox("Menu", list(menus.keys()), key='main_menu')
|
31 |
st.session_state['current_menu'] = selected_menu
|
32 |
|
33 |
# νμ λ©λ΄ μ ν (ν΄λΉλλ κ²½μ°)
|
34 |
if selected_menu in menus:
|
|
|
35 |
selected_sub_menu = st.sidebar.selectbox("Sub Menu", [""] + menus[selected_menu], key=f'sub_menu_{selected_menu}')
|
36 |
st.session_state['current_sub_menu'] = selected_sub_menu
|
37 |
else:
|
38 |
st.session_state['current_sub_menu'] = ''
|
39 |
|
40 |
+
# 'Sound' λ©λ΄μ 'TTS(Voice)' μ ν μ
|
41 |
+
if selected_menu == "Sound" and selected_sub_menu == "TTS(Voice)":
|
42 |
+
st.header("Text-to-Speech")
|
43 |
+
# ν
μ€νΈ μ
λ ₯
|
44 |
+
text = st.text_area("Enter text to synthesize", "Hello, welcome to ViDraft TTS service.")
|
45 |
+
# μΈμ΄ μ ν
|
46 |
+
language = st.selectbox("Choose Language", ["en", "es", "de", "fr", "it", "pt", "ru", "ja", "ko", "zh-cn", "zh-tw"], key='language_select')
|
47 |
|
48 |
+
# 'Synthesize' λ²νΌ
|
49 |
+
if st.button("Synthesize"):
|
50 |
+
if text:
|
51 |
+
try:
|
52 |
+
tts = gTTS(text=text, lang=language, slow=False)
|
53 |
+
audio_file = BytesIO()
|
54 |
+
tts.write_to_fp(audio_file)
|
55 |
+
audio_file.seek(0)
|
56 |
+
st.audio(audio_file, format='audio/mp3')
|
57 |
+
except Exception as e:
|
58 |
+
st.error(f"Error: {e}")
|
59 |
+
else:
|
60 |
+
st.warning("Please enter some text to synthesize.")
|
61 |
+
|
62 |
# Pexels API ν€ μ€μ
|
63 |
PEXELS_API_KEY = "5woz23MGx1QrSY0WHFb0BRi29JvbXPu97Hg0xnklYgHUI8G0w23FKH62"
|
64 |
|
|
|
111 |
components.iframe("https://seawolf2357-gttstest.hf.space", width=None, height=600, scrolling=True)
|
112 |
|
113 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
114 |
|
115 |
# 'Home' νμ΄μ§ νμ
|
116 |
if selected_menu == "Home":
|