haepada commited on
Commit
826c7ae
·
verified ·
1 Parent(s): 4b48dae

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -17
app.py CHANGED
@@ -68,6 +68,10 @@ class SimpleDB:
68
  print(f"Error saving wish: {e}")
69
  return False
70
 
 
 
 
 
71
  # API 설정
72
  HF_API_TOKEN = os.getenv("roots", "") # 기본값을 빈 문자열로 설정
73
  if not HF_API_TOKEN:
@@ -495,7 +499,7 @@ def create_interface():
495
  따뜻한 마음을 담아 작성해주세요.
496
  """)
497
  wishes_display = gr.Dataframe(
498
- headers=["시간", "소원", "감정 분석"],
499
  label="기록된 소원들",
500
  value=[],
501
  interactive=False,
@@ -578,25 +582,26 @@ def handle_image_generation(prompt):
578
  return "소원을 입력해주세요.", []
579
 
580
  try:
581
- current_time = datetime.now().strftime("%H:%M:%S")
582
- if text_analyzer:
583
- sentiment = text_analyzer(text)[0]
584
- sentiment_text = f"{sentiment['label']} ({sentiment['score']:.2f})"
585
- else:
586
- sentiment_text = "분석 불가"
587
-
588
- new_wish = [current_time, text, sentiment_text]
589
- wishes = state.get("wishes", [])
590
- wishes.append(new_wish)
591
- state = {**state, "wishes": wishes}
592
-
593
  # DB에 저장
594
- db.save_wish(state.get("user_name", "익명"), text)
595
-
596
- return "소원이 저장되었습니다.", wishes
 
 
 
 
 
 
 
 
 
 
597
  except Exception as e:
598
  print(f"Error saving wish: {e}")
599
- return "오류가 발생했습니다.", state.get("wishes", [])
600
 
601
  # 버튼 이벤트 연결
602
  start_btn.click(
 
68
  print(f"Error saving wish: {e}")
69
  return False
70
 
71
+ def get_all_wishes(self):
72
+ """모든 소원 반환"""
73
+ return self.wishes
74
+
75
  # API 설정
76
  HF_API_TOKEN = os.getenv("roots", "") # 기본값을 빈 문자열로 설정
77
  if not HF_API_TOKEN:
 
499
  따뜻한 마음을 담아 작성해주세요.
500
  """)
501
  wishes_display = gr.Dataframe(
502
+ headers=["시간", "소원", "이름"], # 헤더 수정
503
  label="기록된 소원들",
504
  value=[],
505
  interactive=False,
 
582
  return "소원을 입력해주세요.", []
583
 
584
  try:
585
+ current_time = datetime.now().strftime("%Y-%m-%d %H:%M:%S") # 날짜 포함
586
+ name = state.get("user_name", "익명")
587
+
 
 
 
 
 
 
 
 
 
588
  # DB에 저장
589
+ db.save_wish(name, text)
590
+
591
+ # 모든 소원 불러오기
592
+ all_wishes = db.wishes # SimpleDB에서 모든 소원 가져오기
593
+
594
+ # 표시할 데이터 형식으로 변환
595
+ wish_display_data = [
596
+ [wish["timestamp"], wish["wish"], wish["name"]]
597
+ for wish in all_wishes
598
+ ]
599
+
600
+ return "소원이 저장되었습니다.", wish_display_data
601
+
602
  except Exception as e:
603
  print(f"Error saving wish: {e}")
604
+ return "오류가 발생했습니다.", []
605
 
606
  # 버튼 이벤트 연결
607
  start_btn.click(