jin2li commited on
Commit
6a2eddc
ยท
verified ยท
1 Parent(s): 05c8f43

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +47 -69
app.py CHANGED
@@ -2573,7 +2573,7 @@ def process_single_ingredient(
2573
 
2574
 
2575
  # ============================================================
2576
- # ํšŒ์›๊ฐ€์ž… ์‹ ์ฒญ / ๊ด€๋ฆฌ์ž ์Šน์ธ / ๋กœ๊ทธ์ธ
2577
  # ============================================================
2578
 
2579
  USER_DB_PATH = os.getenv("USER_DB_PATH", str(BASE_DIR / "users.db"))
@@ -2682,70 +2682,7 @@ def init_user_db():
2682
 
2683
 
2684
  def create_signup_request(team, name, email, password, password_confirm):
2685
- init_user_db()
2686
-
2687
- team = safe_str(team)
2688
- name = safe_str(name)
2689
- email = normalize_email(email)
2690
- password = safe_str(password)
2691
- password_confirm = safe_str(password_confirm)
2692
-
2693
- if not team:
2694
- return "โŒ ํŒ€์„ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”."
2695
- if not name:
2696
- return "โŒ ์ด๋ฆ„์„ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”."
2697
- if not email or "@" not in email:
2698
- return "โŒ ์˜ฌ๋ฐ”๋ฅธ ์ด๋ฉ”์ผ ์ฃผ์†Œ๋ฅผ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”."
2699
- if len(password) < 6:
2700
- return "โŒ ๋น„๋ฐ€๋ฒˆํ˜ธ๋Š” 6์ž ์ด์ƒ์œผ๋กœ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”."
2701
- if password != password_confirm:
2702
- return "โŒ ๋น„๋ฐ€๋ฒˆํ˜ธ์™€ ๋น„๋ฐ€๋ฒˆํ˜ธ ํ™•์ธ์ด ์ผ์น˜ํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค."
2703
-
2704
- conn = get_user_conn()
2705
- cur = conn.cursor()
2706
-
2707
- cur.execute("SELECT status FROM users WHERE email = ?", (email,))
2708
- row = cur.fetchone()
2709
-
2710
- if row:
2711
- status = row["status"]
2712
-
2713
- if status == "approved":
2714
- conn.close()
2715
- return "โŒ ์ด๋ฏธ ์Šน์ธ๋œ ๊ณ„์ •์ž…๋‹ˆ๋‹ค. ๋กœ๊ทธ์ธํ•ด์ฃผ์„ธ์š”."
2716
- if status == "pending":
2717
- conn.close()
2718
- return "โŒ ์ด๋ฏธ ๊ฐ€์ž… ์‹ ์ฒญ์ด ์ ‘์ˆ˜๋œ ๊ณ„์ •์ž…๋‹ˆ๋‹ค. ๊ด€๋ฆฌ์ž ์Šน์ธ์„ ๊ธฐ๋‹ค๋ ค์ฃผ์„ธ์š”."
2719
- if status == "rejected":
2720
- cur.execute(
2721
- """
2722
- UPDATE users
2723
- SET password_hash = ?, name = ?, team = ?, status = 'pending',
2724
- created_at = ?, approved_at = NULL, approved_by = NULL,
2725
- rejected_at = NULL, rejected_by = NULL
2726
- WHERE email = ?
2727
- """,
2728
- (hash_password(password), name, team, now_iso(), email),
2729
- )
2730
- conn.commit()
2731
- conn.close()
2732
- return "โœ… ๊ฐ€์ž… ์‹ ์ฒญ์ด ๋‹ค์‹œ ์ ‘์ˆ˜๋˜์—ˆ์Šต๋‹ˆ๋‹ค. ๊ด€๋ฆฌ์ž ์Šน์ธ ํ›„ ์ด์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค."
2733
-
2734
- cur.execute(
2735
- """
2736
- INSERT INTO users (
2737
- email, password_hash, name, team, status, role, created_at
2738
- )
2739
- VALUES (?, ?, ?, ?, 'pending', 'user', ?)
2740
- """,
2741
- (email, hash_password(password), name, team, now_iso()),
2742
- )
2743
-
2744
- conn.commit()
2745
- conn.close()
2746
-
2747
- return "โœ… ๊ฐ€์ž… ์‹ ์ฒญ์ด ์™„๋ฃŒ๋˜์—ˆ์Šต๋‹ˆ๋‹ค. ๊ด€๋ฆฌ์ž ์Šน์ธ ํ›„ ์ด์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค."
2748
-
2749
 
2750
  def login_user(email, password):
2751
  init_user_db()
@@ -2809,7 +2746,7 @@ def is_admin_user(user):
2809
  def require_login_message():
2810
  return (
2811
  "โŒ ๋กœ๊ทธ์ธ ํ›„ ์ด์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.\n"
2812
- "- ํšŒ์›๊ฐ€์ž… ์‹ ์ฒญ ํ›„ ๊ด€๋ฆฌ์ž๊ฐ€ ์Šน์ธํ•ด์•ผ ์‚ฌ์šฉ ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค.\n"
2813
  "- ์Šน์ธ๋œ ๊ณ„์ •์œผ๋กœ ๋กœ๊ทธ์ธํ•ด์ฃผ์„ธ์š”."
2814
  )
2815
 
@@ -3201,6 +3138,47 @@ def process_single_ingredient_with_auth(user, countries, single_query, single_am
3201
  )
3202
 
3203
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3204
  with gr.Blocks(css=custom_css) as demo:
3205
  current_user = gr.State({})
3206
  session_user_json = gr.Textbox(visible=False, elem_id="rebom_session_user_json")
@@ -3375,8 +3353,8 @@ with gr.Blocks(css=custom_css) as demo:
3375
  logout_btn = gr.Button("๋กœ๊ทธ์•„์›ƒ", variant="secondary")
3376
  login_status = gr.Textbox(label="๋กœ๊ทธ์ธ ์ƒํƒœ", interactive=False, lines=3)
3377
 
3378
- with gr.Tab("๐Ÿ“ ํšŒ์›๊ฐ€์ž… ์‹ ์ฒญ", visible=False):
3379
- gr.Markdown("## ๐Ÿ“ ํšŒ์›๊ฐ€์ž… ์‹ ์ฒญ")
3380
  gr.Markdown("ํŒ€, ์ด๋ฆ„, ๋ฉ”์ผ ์ฃผ์†Œ, ๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ์ž…๋ ฅํ•˜๋ฉด ๊ด€๋ฆฌ์ž ์Šน์ธ ํ›„ ์‚ฌ์ดํŠธ ์ด์šฉ์ด ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค.")
3381
 
3382
  signup_team = gr.Textbox(label="ํŒ€", placeholder="์˜ˆ: ์ „๋žต์ œํ’ˆ์—ฐ๊ตฌํŒ€")
@@ -3384,7 +3362,7 @@ with gr.Blocks(css=custom_css) as demo:
3384
  signup_email = gr.Textbox(label="๋ฉ”์ผ ์ฃผ์†Œ", placeholder="example@rebom.kr")
3385
  signup_password = gr.Textbox(label="๋น„๋ฐ€๋ฒˆํ˜ธ", type="password")
3386
  signup_password_confirm = gr.Textbox(label="๋น„๋ฐ€๋ฒˆํ˜ธ ํ™•์ธ", type="password")
3387
- signup_btn = gr.Button("ํšŒ์›๊ฐ€์ž… ์‹ ์ฒญ", variant="primary")
3388
  signup_status = gr.Textbox(label="์‹ ์ฒญ ์ƒํƒœ", interactive=False, lines=3)
3389
 
3390
  signup_btn.click(
 
2573
 
2574
 
2575
  # ============================================================
2576
+ # ๊ณ„์ • ๋“ฑ๋ก์€ ๊ด€๋ฆฌ์ž์—๊ฒŒ ์š”์ฒญ / ๊ด€๋ฆฌ์ž ์Šน์ธ / ๋กœ๊ทธ์ธ
2577
  # ============================================================
2578
 
2579
  USER_DB_PATH = os.getenv("USER_DB_PATH", str(BASE_DIR / "users.db"))
 
2682
 
2683
 
2684
  def create_signup_request(team, name, email, password, password_confirm):
2685
+ return "โ„น๏ธ ํšŒ์›๊ฐ€์ž… ๊ธฐ๋Šฅ์€ ์‚ฌ์šฉํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค. ๊ด€๋ฆฌ์ž๊ฐ€ app.py์˜ USER_DB์— ๋ฉ”์ผ/๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ์ง์ ‘ ๋“ฑ๋กํ•ฉ๋‹ˆ๋‹ค."
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2686
 
2687
  def login_user(email, password):
2688
  init_user_db()
 
2746
  def require_login_message():
2747
  return (
2748
  "โŒ ๋กœ๊ทธ์ธ ํ›„ ์ด์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.\n"
2749
+ "- ๊ณ„์ • ๋“ฑ๋ก์€ ๊ด€๋ฆฌ์ž์—๊ฒŒ ์š”์ฒญ ํ›„ ๊ด€๋ฆฌ์ž๊ฐ€ ์Šน์ธํ•ด์•ผ ์‚ฌ์šฉ ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค.\n"
2750
  "- ์Šน์ธ๋œ ๊ณ„์ •์œผ๋กœ ๋กœ๊ทธ์ธํ•ด์ฃผ์„ธ์š”."
2751
  )
2752
 
 
3138
  )
3139
 
3140
 
3141
+
3142
+ # ============================================================
3143
+ # ๋กœ๊ทธ์ธ ์ธ์ฆ
3144
+ # - Gradio ๊ธฐ๋ณธ ๋กœ๊ทธ์ธ์ฐฝ ์‚ฌ์šฉ
3145
+ # - ์•„๋ž˜ USER_DB์— ๋ฉ”์ผ/๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ์ง์ ‘ ๋“ฑ๋ก
3146
+ # ============================================================
3147
+ # ์‚ฌ์šฉ์ž ์ถ”๊ฐ€ ๋ฐฉ๋ฒ•:
3148
+ # USER_DB ์•ˆ์— ์•„๋ž˜ ํ˜•์‹์œผ๋กœ ํ•œ ์ค„์”ฉ ์ถ”๊ฐ€ํ•˜์„ธ์š”.
3149
+ # "๋ฉ”์ผ์ฃผ์†Œ": "๋น„๋ฐ€๋ฒˆํ˜ธ",
3150
+ # ============================================================
3151
+
3152
+ USER_DB = {
3153
+ "jin2li@rebom.kr": "qwer0515!",
3154
+
3155
+ # ์‚ฌ์šฉ์ž ๋“ฑ๋ก ์˜ˆ์‹œ:
3156
+ # "yubin.p@rebom.kr": "123456!",
3157
+ # "jkh@rebom.kr": "rebom123!",
3158
+ }
3159
+
3160
+
3161
+ def auth_fn(username, password):
3162
+ username = str(username).strip().lower()
3163
+ password = str(password).strip()
3164
+ return USER_DB.get(username) == password
3165
+
3166
+
3167
+ # Gradio ๊ธฐ๋ณธ auth๋ฅผ ํ†ต๊ณผํ•œ ์‚ฌ์šฉ์ž๋Š” ์ด๋ฏธ ์ธ์ฆ๋œ ์ƒํƒœ์ด๋ฏ€๋กœ ๋‚ด๋ถ€ ๋กœ๊ทธ์ธ ์ฒดํฌ๋ฅผ ํ•˜์ง€ ์•Š๋Š”๋‹ค.
3168
+ def process_with_auth(user, countries, file, product_name="", use_mfds_live=False, live_max_terms=30, live_headless=True):
3169
+ return process(countries, file, product_name, use_mfds_live, live_max_terms, live_headless)
3170
+
3171
+
3172
+ def process_single_ingredient_with_auth(user, countries, single_query, single_amount, single_function, single_use_mfds_live=False):
3173
+ return process_single_ingredient(
3174
+ countries,
3175
+ single_query,
3176
+ single_amount,
3177
+ single_function,
3178
+ single_use_mfds_live,
3179
+ )
3180
+
3181
+
3182
  with gr.Blocks(css=custom_css) as demo:
3183
  current_user = gr.State({})
3184
  session_user_json = gr.Textbox(visible=False, elem_id="rebom_session_user_json")
 
3353
  logout_btn = gr.Button("๋กœ๊ทธ์•„์›ƒ", variant="secondary")
3354
  login_status = gr.Textbox(label="๋กœ๊ทธ์ธ ์ƒํƒœ", interactive=False, lines=3)
3355
 
3356
+ with gr.Tab("๐Ÿ“ ๊ณ„์ • ๋“ฑ๋ก์€ ๊ด€๋ฆฌ์ž์—๊ฒŒ ์š”์ฒญ", visible=False):
3357
+ gr.Markdown("## ๐Ÿ“ ๊ณ„์ • ๋“ฑ๋ก์€ ๊ด€๋ฆฌ์ž์—๊ฒŒ ์š”์ฒญ")
3358
  gr.Markdown("ํŒ€, ์ด๋ฆ„, ๋ฉ”์ผ ์ฃผ์†Œ, ๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ์ž…๋ ฅํ•˜๋ฉด ๊ด€๋ฆฌ์ž ์Šน์ธ ํ›„ ์‚ฌ์ดํŠธ ์ด์šฉ์ด ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค.")
3359
 
3360
  signup_team = gr.Textbox(label="ํŒ€", placeholder="์˜ˆ: ์ „๋žต์ œํ’ˆ์—ฐ๊ตฌํŒ€")
 
3362
  signup_email = gr.Textbox(label="๋ฉ”์ผ ์ฃผ์†Œ", placeholder="example@rebom.kr")
3363
  signup_password = gr.Textbox(label="๋น„๋ฐ€๋ฒˆํ˜ธ", type="password")
3364
  signup_password_confirm = gr.Textbox(label="๋น„๋ฐ€๋ฒˆํ˜ธ ํ™•์ธ", type="password")
3365
+ signup_btn = gr.Button("๊ณ„์ • ๋“ฑ๋ก์€ ๊ด€๋ฆฌ์ž์—๊ฒŒ ์š”์ฒญ", variant="primary")
3366
  signup_status = gr.Textbox(label="์‹ ์ฒญ ์ƒํƒœ", interactive=False, lines=3)
3367
 
3368
  signup_btn.click(