seawolf2357 commited on
Commit
5888805
β€’
1 Parent(s): a43c03b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -29
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
- # μ—¬κΈ°μ„œλΆ€ν„° `selected_menu` λ³€μˆ˜λ₯Ό 기반으둜 쑰건문을 μ‚¬μš©ν•˜λŠ” λ‚˜λ¨Έμ§€ μ½”λ“œκ°€ μ˜¬λ°”λ₯΄κ²Œ μž‘λ™ν•  κ²ƒμž…λ‹ˆλ‹€.
 
 
 
 
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":