haepada commited on
Commit
44d14de
·
verified ·
1 Parent(s): 7469d14

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +109 -5
app.py CHANGED
@@ -163,8 +163,86 @@ def create_interface():
163
  header = gr.Markdown("# 디지털 굿판")
164
  user_display = gr.Markdown("")
165
 
166
- # 나머지 인터페이스 코드는 동일하게 유지...
167
- [이전 코드와 동일한 부분 생략]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
168
 
169
  def analyze_voice(audio_path, state):
170
  """음성 분석"""
@@ -213,10 +291,36 @@ def create_interface():
213
  except Exception as e:
214
  return state, f"오류 발생: {str(e)}", "", "", ""
215
 
216
- # 이벤트 연결도 동일하게 유지...
217
- [이전 코드와 동일한 부분 생략]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
218
 
219
- return app
 
 
 
 
 
 
 
 
 
 
220
 
221
  if __name__ == "__main__":
222
  demo = create_interface()
 
163
  header = gr.Markdown("# 디지털 굿판")
164
  user_display = gr.Markdown("")
165
 
166
+ with gr.Tabs() as tabs:
167
+ # 입장
168
+ with gr.Tab("입장"):
169
+ gr.Markdown("""# 디지털 굿판에 오신 것을 환영합니다""")
170
+ name_input = gr.Textbox(label="이름을 알려주세요")
171
+ start_btn = gr.Button("여정 시작하기")
172
+
173
+ # 청신
174
+ with gr.Tab("청신"):
175
+ with gr.Row():
176
+ audio_path = os.path.abspath(os.path.join("assets", "main_music.mp3"))
177
+ audio = gr.Audio(
178
+ value=audio_path,
179
+ type="filepath",
180
+ label="온천천의 소리",
181
+ interactive=False,
182
+ autoplay=True
183
+ )
184
+ with gr.Column():
185
+ reflection_input = gr.Textbox(
186
+ label="현재 순간의 감상을 적어주세요",
187
+ lines=3
188
+ )
189
+ save_btn = gr.Button("감상 저장하기")
190
+ reflections_display = gr.Dataframe(
191
+ headers=["시간", "감상", "감정 분석"],
192
+ label="기록된 감상들"
193
+ )
194
+
195
+ # 기원
196
+ with gr.Tab("기원"):
197
+ gr.Markdown("## 기원 - 목소리로 전하기")
198
+ with gr.Row():
199
+ with gr.Column():
200
+ voice_input = gr.Audio(
201
+ label="나누고 싶은 이야기를 들려주세요",
202
+ sources=["microphone"],
203
+ type="filepath",
204
+ interactive=True
205
+ )
206
+ clear_btn = gr.Button("녹음 지우기")
207
+
208
+ with gr.Column():
209
+ transcribed_text = gr.Textbox(
210
+ label="인식된 텍스트",
211
+ interactive=False
212
+ )
213
+ voice_emotion = gr.Textbox(
214
+ label="음성 감정 분석",
215
+ interactive=False
216
+ )
217
+ text_emotion = gr.Textbox(
218
+ label="텍스트 감정 분석",
219
+ interactive=False
220
+ )
221
+ analyze_btn = gr.Button("분석하기")
222
+
223
+ # 송신
224
+ with gr.Tab("송신"):
225
+ gr.Markdown("## 송신 - 시각화 결과")
226
+ with gr.Column():
227
+ final_prompt = gr.Textbox(
228
+ label="생성된 프롬프트",
229
+ interactive=False,
230
+ lines=3
231
+ )
232
+ generate_btn = gr.Button("이미지 생성하기")
233
+ result_image = gr.Image(
234
+ label="생성된 이미지",
235
+ type="pil"
236
+ )
237
+
238
+ # 인터페이스 함수들
239
+ def start_journey(name):
240
+ """여정 시작"""
241
+ return f"# 환영합니다, {name}님의 디지털 굿판", gr.update(selected="청신")
242
+
243
+ def clear_voice_input():
244
+ """음성 입력 초기화"""
245
+ return None
246
 
247
  def analyze_voice(audio_path, state):
248
  """음성 분석"""
 
291
  except Exception as e:
292
  return state, f"오류 발생: {str(e)}", "", "", ""
293
 
294
+ # 이벤트 연결
295
+ start_btn.click(
296
+ fn=lambda name: (f"# 환영합니다, {name}님의 디지털 굿판", gr.update(selected="청신")),
297
+ inputs=[name_input],
298
+ outputs=[user_display, tabs]
299
+ )
300
+
301
+ save_btn.click(
302
+ fn=save_reflection,
303
+ inputs=[reflection_input, state],
304
+ outputs=[state, reflections_display]
305
+ )
306
+
307
+ clear_btn.click(
308
+ fn=clear_voice_input,
309
+ inputs=[],
310
+ outputs=[voice_input]
311
+ )
312
 
313
+ analyze_btn.click(
314
+ fn=analyze_voice,
315
+ inputs=[voice_input, state],
316
+ outputs=[state, transcribed_text, voice_emotion, text_emotion, final_prompt]
317
+ )
318
+
319
+ generate_btn.click(
320
+ fn=generate_image_from_prompt,
321
+ inputs=[final_prompt],
322
+ outputs=[result_image]
323
+ )
324
 
325
  if __name__ == "__main__":
326
  demo = create_interface()