seawolf2357 commited on
Commit
4862dc2
β€’
1 Parent(s): 2f686d1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +41 -12
app.py CHANGED
@@ -1,6 +1,9 @@
1
  import streamlit as st
2
  import requests
3
-
 
 
 
4
 
5
  # νŽ˜μ΄μ§€ μ„€μ •
6
  st.set_page_config(page_title="ViDraft", layout="wide")
@@ -24,19 +27,20 @@ if 'current_menu' not in st.session_state:
24
  if 'current_sub_menu' not in st.session_state:
25
  st.session_state['current_sub_menu'] = ''
26
 
27
- # 메인 메뉴 선택
28
- selected_menu = st.sidebar.selectbox("Menu", list(menus.keys()))
29
  st.session_state['current_menu'] = selected_menu
30
 
31
- # μ—¬κΈ°μ—μ„œ `selected_menu` λ³€μˆ˜κ°€ 이미 μ •μ˜λ˜μ—ˆμŠ΅λ‹ˆλ‹€. 이제 ν•˜μœ„ 메뉴 선택 이후 μ‚¬μš©μ΄ μ‹œμž‘λ©λ‹ˆλ‹€.
32
-
33
  # ν•˜μœ„ 메뉴 선택 (ν•΄λ‹Ήλ˜λŠ” 경우)
34
  if selected_menu in menus:
35
- selected_sub_menu = st.sidebar.selectbox("Sub Menu", [""] + menus[selected_menu])
 
36
  st.session_state['current_sub_menu'] = selected_sub_menu
37
  else:
38
  st.session_state['current_sub_menu'] = ''
39
 
 
 
40
  # μ—¬κΈ°μ„œλΆ€ν„° `selected_menu` λ³€μˆ˜λ₯Ό 기반으둜 쑰건문을 μ‚¬μš©ν•˜λŠ” λ‚˜λ¨Έμ§€ μ½”λ“œκ°€ μ˜¬λ°”λ₯΄κ²Œ μž‘λ™ν•  κ²ƒμž…λ‹ˆλ‹€.
41
 
42
  # Pexels API ν‚€ μ„€μ •
@@ -84,7 +88,37 @@ if selected_menu == "Free Stock" and st.session_state['current_sub_menu'] == "Se
84
  with cols[idx % 3]:
85
  st.video(video)
86
 
 
 
 
 
 
 
87
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
88
  # 'Home' νŽ˜μ΄μ§€ ν‘œμ‹œ
89
  if selected_menu == "Home":
90
  st.header("Welcome to ViDraft")
@@ -114,9 +148,7 @@ elif selected_menu == "Image":
114
  elif st.session_state['current_sub_menu'] == "Inpainting":
115
  st.header("Inpainting")
116
  st.write("Fill in missing parts of images.")
117
- elif st.session_state['current_sub_menu'] == "Remove Background":
118
- st.header("Remove Background")
119
- st.write("Easily remove backgrounds from images.")
120
  elif st.session_state['current_sub_menu'] == "Studio":
121
  st.header("Image Studio")
122
  st.write("Access a suite of image editing tools.")
@@ -144,9 +176,6 @@ elif selected_menu == "Sound":
144
  elif st.session_state['current_sub_menu'] == "Video Music":
145
  st.header("Video Music")
146
  st.write("Find the perfect music for your video content.")
147
- elif st.session_state['current_sub_menu'] == "TTS(Voice)":
148
- st.header("Text-to-Speech")
149
- st.write("Convert your text into natural-sounding voice.")
150
  elif st.session_state['current_sub_menu'] == "Image SFX":
151
  st.header("Image Sound Effects")
152
  st.write("Add sound effects to your images.")
 
1
  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
  # νŽ˜μ΄μ§€ μ„€μ •
9
  st.set_page_config(page_title="ViDraft", layout="wide")
 
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 ν‚€ μ„€μ •
 
88
  with cols[idx % 3]:
89
  st.video(video)
90
 
91
+ # 'Image' λ©”λ‰΄μ—μ„œ 'Remove Background' 선택 μ‹œ
92
+ if selected_menu == "Image" and st.session_state['current_sub_menu'] == "Remove Background":
93
+ st.header("Remove Background")
94
+ # iframe을 μ‚¬μš©ν•˜μ—¬ μ™ΈλΆ€ URL μž„λ² λ“œ
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":
124
  st.header("Welcome to ViDraft")
 
148
  elif st.session_state['current_sub_menu'] == "Inpainting":
149
  st.header("Inpainting")
150
  st.write("Fill in missing parts of images.")
151
+
 
 
152
  elif st.session_state['current_sub_menu'] == "Studio":
153
  st.header("Image Studio")
154
  st.write("Access a suite of image editing tools.")
 
176
  elif st.session_state['current_sub_menu'] == "Video Music":
177
  st.header("Video Music")
178
  st.write("Find the perfect music for your video content.")
 
 
 
179
  elif st.session_state['current_sub_menu'] == "Image SFX":
180
  st.header("Image Sound Effects")
181
  st.write("Add sound effects to your images.")