haepada commited on
Commit
6671fa4
·
verified ·
1 Parent(s): 4fc8759

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +105 -106
app.py CHANGED
@@ -325,127 +325,126 @@ def create_interface():
325
  baseline_audio = gr.Audio(
326
  label="축원 문장 녹음하기",
327
  sources=["microphone"]
328
- )
329
  set_baseline_btn = gr.Button("기준점 설정 완료")
330
  baseline_status = gr.Markdown("")
331
 
332
- with gr.Tab("청신"):
333
  gr.Markdown("## 청신 - 소리로 정화하기")
334
  play_music_btn = gr.Button("온천천의 소리 듣기")
335
  with gr.Row():
336
- audio = gr.Audio(
337
- value=None,
338
- type="filepath",
339
- label="온천천의 소리",
340
- interactive=False,
341
- autoplay=False
342
- )
343
- with gr.Column():
344
- reflection_input = gr.Textbox(
345
- label="지금 이 순간의 감상을 자유롭게 적어보세요",
346
- lines=3
347
- )
348
- save_btn = gr.Button("감상 저장하기")
349
- reflections_display = gr.Dataframe(
350
- headers=["시간", "감상", "감정 분석"],
351
- label="기록된 감상들"
352
- )
353
-
354
- with gr.Tab("기원"):
355
  gr.Markdown("## 기원 - 소원을 전해보세요")
356
  with gr.Row():
357
- with gr.Column():
358
- voice_input = gr.Audio(
359
- label="소원을 나누고 싶은 마음을 말해주세요",
360
- sources=["microphone"]
361
- )
362
- clear_btn = gr.Button("녹음 지우기")
363
- analyze_btn = gr.Button("소원 분석하기")
364
-
365
- with gr.Column():
366
- transcribed_text = gr.Textbox(label="인식된 텍스트")
367
- voice_emotion = gr.Textbox(label="음성 감정 분석")
368
- text_emotion = gr.Textbox(label="텍스트 감정 분석")
369
-
370
- with gr.Tab("송신"):
371
  gr.Markdown("## 송신 - 마음의 그림을 남기고, 보내기")
372
  final_prompt = gr.Textbox(
373
- label="생성된 프롬프트",
374
- interactive=False,
375
- lines=3
376
- )
377
  generate_btn = gr.Button("마음의 그림 그리기")
378
  result_image = gr.Image(label="생성된 이미지")
379
-
380
  gr.Markdown("## 마지막 감상을 남겨주세요")
381
  final_reflection = gr.Textbox(
382
- label="마지막 감상",
383
- placeholder="한 줄로 남겨주세요..."
384
- )
385
  save_final_btn = gr.Button("감상 남기기")
386
 
387
- def delayed_image_clear():
388
- time.sleep(IMAGE_DISPLAY_TIME)
389
- return gr.update(value=None)
390
-
391
- def on_image_generated(prompt):
392
- image_content = generate_image_from_prompt(prompt)
393
- if image_content:
394
- # Start a timer to clear the image
395
- timer = threading.Timer(IMAGE_DISPLAY_TIME, lambda: result_image.update(value=None))
396
- timer.start()
397
- return image_content
398
- return None
399
-
400
- # 이벤트 연결
401
- start_btn.click(
402
- fn=lambda name: (
403
- WORLDVIEW_MESSAGE if name.strip() else "이름을 입력해주세요",
404
- gr.update(visible=True) if name.strip() else gr.update(),
405
- {"user_name": name} if name.strip() else state
406
- ),
407
- inputs=[name_input],
408
- outputs=[worldview_display, tabs, state]
409
- )
410
-
411
- set_baseline_btn.click(
412
- fn=lambda x, s: ({"baseline_features": calculate_baseline_features(x)}, "기준점이 설정되었습니다."),
413
- inputs=[baseline_audio, state],
414
- outputs=[state, baseline_status]
415
- )
416
-
417
- save_btn.click(
418
- fn=save_reflection,
419
- inputs=[reflection_input, state],
420
- outputs=[state, reflections_display]
421
- )
422
-
423
- clear_btn.click(
424
- fn=lambda: None,
425
- outputs=[voice_input]
426
- )
427
-
428
- analyze_btn.click(
429
- fn=analyze_voice,
430
- inputs=[voice_input, state],
431
- outputs=[state, transcribed_text, voice_emotion, text_emotion, final_prompt]
432
- )
433
-
434
- generate_btn.click(
435
- fn=on_image_generated,
436
- inputs=[final_prompt],
437
- outputs=[result_image]
438
- )
439
-
440
- save_final_btn.click(
441
- fn=lambda t, s: (db.save_wish(s["user_name"], t), "감상이 저장되었습니다."),
442
- inputs=[final_reflection, state],
443
- outputs=[gr.Markdown("")]
444
- )
445
-
446
- return app
447
 
448
  if __name__ == "__main__":
449
- demo = create_interface()
450
- demo.launch(debug=True)
451
-
 
325
  baseline_audio = gr.Audio(
326
  label="축원 문장 녹음하기",
327
  sources=["microphone"]
328
+ )
329
  set_baseline_btn = gr.Button("기준점 설정 완료")
330
  baseline_status = gr.Markdown("")
331
 
332
+ with gr.Tab("청신"):
333
  gr.Markdown("## 청신 - 소리로 정화하기")
334
  play_music_btn = gr.Button("온천천의 소리 듣기")
335
  with gr.Row():
336
+ audio = gr.Audio(
337
+ value=None,
338
+ type="filepath",
339
+ label="온천천의 소리",
340
+ interactive=False,
341
+ autoplay=False
342
+ )
343
+ with gr.Column():
344
+ reflection_input = gr.Textbox(
345
+ label="지금 이 순간의 감상을 자유롭게 적어보세요",
346
+ lines=3
347
+ )
348
+ save_btn = gr.Button("감상 저장하기")
349
+ reflections_display = gr.Dataframe(
350
+ headers=["시간", "감상", "감정 분석"],
351
+ label="기록된 감상들"
352
+ )
353
+
354
+ with gr.Tab("기원"):
355
  gr.Markdown("## 기원 - 소원을 전해보세요")
356
  with gr.Row():
357
+ with gr.Column():
358
+ voice_input = gr.Audio(
359
+ label="소원을 나누고 싶은 마음을 말해주세요",
360
+ sources=["microphone"]
361
+ )
362
+ clear_btn = gr.Button("녹음 지우기")
363
+ analyze_btn = gr.Button("소원 분석하기")
364
+
365
+ with gr.Column():
366
+ transcribed_text = gr.Textbox(label="인식된 텍스트")
367
+ voice_emotion = gr.Textbox(label="음성 감정 분석")
368
+ text_emotion = gr.Textbox(label="텍스트 감정 분석")
369
+
370
+ with gr.Tab("송신"):
371
  gr.Markdown("## 송신 - 마음의 그림을 남기고, 보내기")
372
  final_prompt = gr.Textbox(
373
+ label="생성된 프롬프트",
374
+ interactive=False,
375
+ lines=3
376
+ )
377
  generate_btn = gr.Button("마음의 그림 그리기")
378
  result_image = gr.Image(label="생성된 이미지")
379
+
380
  gr.Markdown("## 마지막 감상을 남겨주세요")
381
  final_reflection = gr.Textbox(
382
+ label="마지막 감상",
383
+ placeholder="한 줄로 남겨주세요..."
384
+ )
385
  save_final_btn = gr.Button("감상 남기기")
386
 
387
+ def delayed_image_clear():
388
+ time.sleep(IMAGE_DISPLAY_TIME)
389
+ return gr.update(value=None)
390
+
391
+ def on_image_generated(prompt):
392
+ image_content = generate_image_from_prompt(prompt)
393
+ if image_content:
394
+ # Start a timer to clear the image
395
+ timer = threading.Timer(IMAGE_DISPLAY_TIME, lambda: result_image.update(value=None))
396
+ timer.start()
397
+ return image_content
398
+ return None
399
+
400
+ # 이벤트 연결
401
+ start_btn.click(
402
+ fn=lambda name: (
403
+ WORLDVIEW_MESSAGE if name.strip() else "이름을 입력해주세요",
404
+ gr.update(visible=True) if name.strip() else gr.update(),
405
+ {"user_name": name} if name.strip() else state
406
+ ),
407
+ inputs=[name_input],
408
+ outputs=[worldview_display, tabs, state]
409
+ )
410
+
411
+ set_baseline_btn.click(
412
+ fn=lambda x, s: ({"baseline_features": calculate_baseline_features(x)}, "기준점이 설정되었습니다."),
413
+ inputs=[baseline_audio, state],
414
+ outputs=[state, baseline_status]
415
+ )
416
+
417
+ save_btn.click(
418
+ fn=save_reflection,
419
+ inputs=[reflection_input, state],
420
+ outputs=[state, reflections_display]
421
+ )
422
+
423
+ clear_btn.click(
424
+ fn=lambda: None,
425
+ outputs=[voice_input]
426
+ )
427
+
428
+ analyze_btn.click(
429
+ fn=analyze_voice,
430
+ inputs=[voice_input, state],
431
+ outputs=[state, transcribed_text, voice_emotion, text_emotion, final_prompt]
432
+ )
433
+
434
+ generate_btn.click(
435
+ fn=on_image_generated,
436
+ inputs=[final_prompt],
437
+ outputs=[result_image]
438
+ )
439
+
440
+ save_final_btn.click(
441
+ fn=lambda t, s: (db.save_wish(s["user_name"], t), "감상이 저장되었습니다."),
442
+ inputs=[final_reflection, state],
443
+ outputs=[gr.Markdown("")]
444
+ )
445
+
446
+ return app
447
 
448
  if __name__ == "__main__":
449
+ demo = create_interface()
450
+ demo.launch(debug=True)