Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -2623,108 +2623,6 @@ def verify_password(password, stored_hash):
|
|
| 2623 |
return secrets.compare_digest(check, digest)
|
| 2624 |
|
| 2625 |
|
| 2626 |
-
def get_user_conn():
|
| 2627 |
-
conn = sqlite3.connect(USER_DB_PATH)
|
| 2628 |
-
conn.row_factory = sqlite3.Row
|
| 2629 |
-
return conn
|
| 2630 |
-
|
| 2631 |
-
|
| 2632 |
-
def init_user_db():
|
| 2633 |
-
conn = get_user_conn()
|
| 2634 |
-
cur = conn.cursor()
|
| 2635 |
-
|
| 2636 |
-
cur.execute(
|
| 2637 |
-
"""
|
| 2638 |
-
CREATE TABLE IF NOT EXISTS users (
|
| 2639 |
-
email TEXT PRIMARY KEY,
|
| 2640 |
-
password_hash TEXT NOT NULL,
|
| 2641 |
-
name TEXT NOT NULL,
|
| 2642 |
-
team TEXT NOT NULL,
|
| 2643 |
-
status TEXT NOT NULL DEFAULT 'pending',
|
| 2644 |
-
role TEXT NOT NULL DEFAULT 'user',
|
| 2645 |
-
created_at TEXT NOT NULL,
|
| 2646 |
-
approved_at TEXT,
|
| 2647 |
-
approved_by TEXT,
|
| 2648 |
-
rejected_at TEXT,
|
| 2649 |
-
rejected_by TEXT
|
| 2650 |
-
)
|
| 2651 |
-
"""
|
| 2652 |
-
)
|
| 2653 |
-
|
| 2654 |
-
conn.commit()
|
| 2655 |
-
|
| 2656 |
-
# ์ต์ด ๊ด๋ฆฌ์ ๊ณ์ ์๋ ์์ฑ
|
| 2657 |
-
cur.execute("SELECT email FROM users WHERE email = ?", (DEFAULT_ADMIN_EMAIL,))
|
| 2658 |
-
exists = cur.fetchone()
|
| 2659 |
-
|
| 2660 |
-
if not exists:
|
| 2661 |
-
cur.execute(
|
| 2662 |
-
"""
|
| 2663 |
-
INSERT INTO users (
|
| 2664 |
-
email, password_hash, name, team, status, role,
|
| 2665 |
-
created_at, approved_at, approved_by
|
| 2666 |
-
)
|
| 2667 |
-
VALUES (?, ?, ?, ?, 'approved', 'admin', ?, ?, ?)
|
| 2668 |
-
""",
|
| 2669 |
-
(
|
| 2670 |
-
DEFAULT_ADMIN_EMAIL,
|
| 2671 |
-
hash_password(DEFAULT_ADMIN_PASSWORD),
|
| 2672 |
-
"๊ด๋ฆฌ์",
|
| 2673 |
-
"ADMIN",
|
| 2674 |
-
now_iso(),
|
| 2675 |
-
now_iso(),
|
| 2676 |
-
"system",
|
| 2677 |
-
),
|
| 2678 |
-
)
|
| 2679 |
-
conn.commit()
|
| 2680 |
-
|
| 2681 |
-
conn.close()
|
| 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()
|
| 2689 |
-
|
| 2690 |
-
email = normalize_email(email)
|
| 2691 |
-
password = safe_str(password)
|
| 2692 |
-
|
| 2693 |
-
if not email or not password:
|
| 2694 |
-
return {}, "โ ์ด๋ฉ์ผ๊ณผ ๋น๋ฐ๋ฒํธ๋ฅผ ์
๋ ฅํด์ฃผ์ธ์."
|
| 2695 |
-
|
| 2696 |
-
conn = get_user_conn()
|
| 2697 |
-
cur = conn.cursor()
|
| 2698 |
-
cur.execute("SELECT * FROM users WHERE email = ?", (email,))
|
| 2699 |
-
row = cur.fetchone()
|
| 2700 |
-
conn.close()
|
| 2701 |
-
|
| 2702 |
-
if not row:
|
| 2703 |
-
return {}, "โ ๋ฑ๋ก๋์ง ์์ ์ด๋ฉ์ผ์
๋๋ค."
|
| 2704 |
-
|
| 2705 |
-
if not verify_password(password, row["password_hash"]):
|
| 2706 |
-
return {}, "โ ๋น๋ฐ๋ฒํธ๊ฐ ์ผ์นํ์ง ์์ต๋๋ค."
|
| 2707 |
-
|
| 2708 |
-
if row["status"] == "pending":
|
| 2709 |
-
return {}, "โณ ๊ฐ์
์ ์ฒญ์ ์๋ฃ๋์์ง๋ง ์์ง ๊ด๋ฆฌ์ ์น์ธ ๋๊ธฐ ์ค์
๋๋ค."
|
| 2710 |
-
|
| 2711 |
-
if row["status"] == "rejected":
|
| 2712 |
-
return {}, "โ ๊ด๋ฆฌ์๊ฐ ๊ฐ์
์ ์ฒญ์ ๊ฑฐ์ ํ ๊ณ์ ์
๋๋ค."
|
| 2713 |
-
|
| 2714 |
-
if row["status"] != "approved":
|
| 2715 |
-
return {}, "โ ์ฌ์ฉํ ์ ์๋ ๊ณ์ ์ํ์
๋๋ค."
|
| 2716 |
-
|
| 2717 |
-
user = {
|
| 2718 |
-
"email": row["email"],
|
| 2719 |
-
"name": row["name"],
|
| 2720 |
-
"team": row["team"],
|
| 2721 |
-
"role": row["role"],
|
| 2722 |
-
"status": row["status"],
|
| 2723 |
-
}
|
| 2724 |
-
|
| 2725 |
-
return user, f"โ
๋ก๊ทธ์ธ ์๋ฃ: {row['team']} / {row['name']} / {row['email']}"
|
| 2726 |
-
|
| 2727 |
-
|
| 2728 |
def logout_user():
|
| 2729 |
return {}, "๐ช ๋ก๊ทธ์์๋์์ต๋๋ค."
|
| 2730 |
|
|
@@ -2773,199 +2671,6 @@ def process_single_ingredient_with_auth(user, countries, single_query, single_am
|
|
| 2773 |
)
|
| 2774 |
|
| 2775 |
|
| 2776 |
-
def users_to_dataframe(status_filter="pending"):
|
| 2777 |
-
init_user_db()
|
| 2778 |
-
|
| 2779 |
-
status_filter = safe_str(status_filter)
|
| 2780 |
-
|
| 2781 |
-
conn = get_user_conn()
|
| 2782 |
-
cur = conn.cursor()
|
| 2783 |
-
|
| 2784 |
-
if status_filter and status_filter != "์ ์ฒด":
|
| 2785 |
-
cur.execute(
|
| 2786 |
-
"""
|
| 2787 |
-
SELECT email, name, team, status, role, created_at, approved_at, approved_by, rejected_at, rejected_by
|
| 2788 |
-
FROM users
|
| 2789 |
-
WHERE status = ?
|
| 2790 |
-
ORDER BY created_at DESC
|
| 2791 |
-
""",
|
| 2792 |
-
(status_filter,),
|
| 2793 |
-
)
|
| 2794 |
-
else:
|
| 2795 |
-
cur.execute(
|
| 2796 |
-
"""
|
| 2797 |
-
SELECT email, name, team, status, role, created_at, approved_at, approved_by, rejected_at, rejected_by
|
| 2798 |
-
FROM users
|
| 2799 |
-
ORDER BY created_at DESC
|
| 2800 |
-
"""
|
| 2801 |
-
)
|
| 2802 |
-
|
| 2803 |
-
rows = [dict(r) for r in cur.fetchall()]
|
| 2804 |
-
conn.close()
|
| 2805 |
-
|
| 2806 |
-
columns = [
|
| 2807 |
-
"email", "name", "team", "status", "role",
|
| 2808 |
-
"created_at", "approved_at", "approved_by", "rejected_at", "rejected_by",
|
| 2809 |
-
]
|
| 2810 |
-
|
| 2811 |
-
return pd.DataFrame(rows, columns=columns)
|
| 2812 |
-
|
| 2813 |
-
|
| 2814 |
-
def admin_load_users(user, status_filter):
|
| 2815 |
-
if not is_admin_user(user):
|
| 2816 |
-
return pd.DataFrame(), "โ ๊ด๋ฆฌ์๋ง ํ์ ์น์ธ ๋ชฉ๋ก์ ๋ณผ ์ ์์ต๋๋ค."
|
| 2817 |
-
|
| 2818 |
-
df = users_to_dataframe(status_filter)
|
| 2819 |
-
return df, f"โ
ํ์ ๋ชฉ๋ก ์กฐํ ์๋ฃ: {len(df)}๋ช
"
|
| 2820 |
-
|
| 2821 |
-
|
| 2822 |
-
def admin_approve_user(user, target_email):
|
| 2823 |
-
if not is_admin_user(user):
|
| 2824 |
-
return pd.DataFrame(), "โ ๊ด๋ฆฌ์๋ง ์น์ธํ ์ ์์ต๋๋ค."
|
| 2825 |
-
|
| 2826 |
-
target_email = normalize_email(target_email)
|
| 2827 |
-
|
| 2828 |
-
if not target_email:
|
| 2829 |
-
return users_to_dataframe("pending"), "โ ์น์ธํ ์ด๋ฉ์ผ์ ์
๋ ฅํด์ฃผ์ธ์."
|
| 2830 |
-
|
| 2831 |
-
conn = get_user_conn()
|
| 2832 |
-
cur = conn.cursor()
|
| 2833 |
-
cur.execute("SELECT email FROM users WHERE email = ?", (target_email,))
|
| 2834 |
-
row = cur.fetchone()
|
| 2835 |
-
|
| 2836 |
-
if not row:
|
| 2837 |
-
conn.close()
|
| 2838 |
-
return users_to_dataframe("pending"), "โ ํด๋น ์ด๋ฉ์ผ์ ๊ฐ์
์ ์ฒญ์ ์ฐพ์ ์ ์์ต๋๋ค."
|
| 2839 |
-
|
| 2840 |
-
cur.execute(
|
| 2841 |
-
"""
|
| 2842 |
-
UPDATE users
|
| 2843 |
-
SET status = 'approved',
|
| 2844 |
-
approved_at = ?,
|
| 2845 |
-
approved_by = ?,
|
| 2846 |
-
rejected_at = NULL,
|
| 2847 |
-
rejected_by = NULL
|
| 2848 |
-
WHERE email = ?
|
| 2849 |
-
""",
|
| 2850 |
-
(now_iso(), user.get("email", ""), target_email),
|
| 2851 |
-
)
|
| 2852 |
-
|
| 2853 |
-
conn.commit()
|
| 2854 |
-
conn.close()
|
| 2855 |
-
|
| 2856 |
-
return users_to_dataframe("pending"), f"โ
์น์ธ ์๋ฃ: {target_email}"
|
| 2857 |
-
|
| 2858 |
-
|
| 2859 |
-
def admin_reject_user(user, target_email):
|
| 2860 |
-
if not is_admin_user(user):
|
| 2861 |
-
return pd.DataFrame(), "โ ๊ด๋ฆฌ์๋ง ๊ฑฐ์ ํ ์ ์์ต๋๋ค."
|
| 2862 |
-
|
| 2863 |
-
target_email = normalize_email(target_email)
|
| 2864 |
-
|
| 2865 |
-
if not target_email:
|
| 2866 |
-
return users_to_dataframe("pending"), "โ ๊ฑฐ์ ํ ์ด๋ฉ์ผ์ ์
๋ ฅํด์ฃผ์ธ์."
|
| 2867 |
-
|
| 2868 |
-
conn = get_user_conn()
|
| 2869 |
-
cur = conn.cursor()
|
| 2870 |
-
cur.execute("SELECT email FROM users WHERE email = ?", (target_email,))
|
| 2871 |
-
row = cur.fetchone()
|
| 2872 |
-
|
| 2873 |
-
if not row:
|
| 2874 |
-
conn.close()
|
| 2875 |
-
return users_to_dataframe("pending"), "โ ํด๋น ์ด๋ฉ์ผ์ ๊ฐ์
์ ์ฒญ์ ์ฐพ์ ์ ์์ต๋๋ค."
|
| 2876 |
-
|
| 2877 |
-
if target_email in ADMIN_EMAILS:
|
| 2878 |
-
conn.close()
|
| 2879 |
-
return users_to_dataframe("pending"), "โ ๊ด๋ฆฌ์ ๊ธฐ๋ณธ ๊ณ์ ์ ๊ฑฐ์ ํ ์ ์์ต๋๋ค."
|
| 2880 |
-
|
| 2881 |
-
cur.execute(
|
| 2882 |
-
"""
|
| 2883 |
-
UPDATE users
|
| 2884 |
-
SET status = 'rejected',
|
| 2885 |
-
rejected_at = ?,
|
| 2886 |
-
rejected_by = ?
|
| 2887 |
-
WHERE email = ?
|
| 2888 |
-
""",
|
| 2889 |
-
(now_iso(), user.get("email", ""), target_email),
|
| 2890 |
-
)
|
| 2891 |
-
|
| 2892 |
-
conn.commit()
|
| 2893 |
-
conn.close()
|
| 2894 |
-
|
| 2895 |
-
return users_to_dataframe("pending"), f"โ
๊ฑฐ์ ์๋ฃ: {target_email}"
|
| 2896 |
-
|
| 2897 |
-
|
| 2898 |
-
def login_user_with_ui(email, password):
|
| 2899 |
-
user, message = login_user(email, password)
|
| 2900 |
-
|
| 2901 |
-
if not is_approved_user(user):
|
| 2902 |
-
return (
|
| 2903 |
-
user,
|
| 2904 |
-
message,
|
| 2905 |
-
gr.update(visible=False), # screening_tab
|
| 2906 |
-
gr.update(visible=False), # single_tab
|
| 2907 |
-
gr.update(visible=False), # admin_tab
|
| 2908 |
-
)
|
| 2909 |
-
|
| 2910 |
-
return (
|
| 2911 |
-
user,
|
| 2912 |
-
message,
|
| 2913 |
-
gr.update(visible=True), # screening_tab
|
| 2914 |
-
gr.update(visible=True), # single_tab
|
| 2915 |
-
gr.update(visible=is_admin_user(user)), # admin_tab
|
| 2916 |
-
)
|
| 2917 |
-
|
| 2918 |
-
|
| 2919 |
-
def logout_user_with_ui():
|
| 2920 |
-
user, message = logout_user()
|
| 2921 |
-
|
| 2922 |
-
return (
|
| 2923 |
-
user,
|
| 2924 |
-
message,
|
| 2925 |
-
gr.update(visible=False), # screening_tab
|
| 2926 |
-
gr.update(visible=False), # single_tab
|
| 2927 |
-
gr.update(visible=False), # admin_tab
|
| 2928 |
-
)
|
| 2929 |
-
|
| 2930 |
-
|
| 2931 |
-
|
| 2932 |
-
def admin_delete_user(user, target_email):
|
| 2933 |
-
if not is_admin_user(user):
|
| 2934 |
-
return pd.DataFrame(), "โ ๊ด๋ฆฌ์๋ง ์ญ์ ํ ์ ์์ต๋๋ค."
|
| 2935 |
-
|
| 2936 |
-
target_email = normalize_email(target_email)
|
| 2937 |
-
|
| 2938 |
-
if not target_email:
|
| 2939 |
-
return users_to_dataframe("์ ์ฒด"), "โ ์ญ์ ํ ์ด๋ฉ์ผ์ ์
๋ ฅํด์ฃผ์ธ์."
|
| 2940 |
-
|
| 2941 |
-
admin_email = normalize_email(user.get("email", ""))
|
| 2942 |
-
|
| 2943 |
-
if target_email == admin_email:
|
| 2944 |
-
return users_to_dataframe("์ ์ฒด"), "โ ํ์ฌ ๋ก๊ทธ์ธํ ๊ด๋ฆฌ์ ๋ณธ์ธ ๊ณ์ ์ ์ญ์ ํ ์ ์์ต๋๋ค."
|
| 2945 |
-
|
| 2946 |
-
if target_email in ADMIN_EMAILS:
|
| 2947 |
-
return users_to_dataframe("์ ์ฒด"), "โ ๊ธฐ๋ณธ ๊ด๋ฆฌ์ ๊ณ์ ์ ์ญ์ ํ ์ ์์ต๋๋ค."
|
| 2948 |
-
|
| 2949 |
-
conn = get_user_conn()
|
| 2950 |
-
cur = conn.cursor()
|
| 2951 |
-
cur.execute("SELECT email, role FROM users WHERE email = ?", (target_email,))
|
| 2952 |
-
row = cur.fetchone()
|
| 2953 |
-
|
| 2954 |
-
if not row:
|
| 2955 |
-
conn.close()
|
| 2956 |
-
return users_to_dataframe("์ ์ฒด"), "โ ํด๋น ์ด๋ฉ์ผ์ ํ์ ์ ๋ณด๋ฅผ ์ฐพ์ ์ ์์ต๋๋ค."
|
| 2957 |
-
|
| 2958 |
-
if safe_str(row["role"]) == "admin":
|
| 2959 |
-
conn.close()
|
| 2960 |
-
return users_to_dataframe("์ ์ฒด"), "โ ๊ด๋ฆฌ์ ๊ถํ ๊ณ์ ์ ์ญ์ ํ ์ ์์ต๋๋ค."
|
| 2961 |
-
|
| 2962 |
-
cur.execute("DELETE FROM users WHERE email = ?", (target_email,))
|
| 2963 |
-
conn.commit()
|
| 2964 |
-
conn.close()
|
| 2965 |
-
|
| 2966 |
-
return users_to_dataframe("์ ์ฒด"), f"โ
ํ์ ์ญ์ ์๋ฃ: {target_email}"
|
| 2967 |
-
|
| 2968 |
-
|
| 2969 |
def pick_user_email_from_table(evt):
|
| 2970 |
"""
|
| 2971 |
ํ์ ๋ชฉ๋ก ํ์์ ํ์ ํด๋ฆญํ๋ฉด ํด๋น ํ์ email์ ์น์ธ/๊ฑฐ์ /์ญ์ ์
๋ ฅ์นธ์ ์๋ ์
๋ ฅํ๋ค.
|
|
@@ -2987,80 +2692,33 @@ def pick_user_email_from_table(evt):
|
|
| 2987 |
return ""
|
| 2988 |
|
| 2989 |
|
| 2990 |
-
def
|
| 2991 |
-
|
| 2992 |
-
|
| 2993 |
-
sessionStorage์ ์ ์ฅ๋ ์ฌ์ฉ์ ์ ๋ณด๋ฅผ ๋ค์ current_user gr.State์ ๋ฃ๊ณ ํญ ํ์๋ฅผ ๋ณต๊ตฌํ๋ค.
|
| 2994 |
-
"""
|
| 2995 |
-
try:
|
| 2996 |
-
user = json.loads(safe_str(session_json))
|
| 2997 |
-
except Exception:
|
| 2998 |
-
user = {}
|
| 2999 |
-
|
| 3000 |
-
if not is_approved_user(user):
|
| 3001 |
-
return (
|
| 3002 |
-
{},
|
| 3003 |
-
"",
|
| 3004 |
-
gr.update(visible=False),
|
| 3005 |
-
gr.update(visible=False),
|
| 3006 |
-
gr.update(visible=False),
|
| 3007 |
-
)
|
| 3008 |
-
|
| 3009 |
-
return (
|
| 3010 |
-
user,
|
| 3011 |
-
f"โ
๋ก๊ทธ์ธ ์ ์ง ์ค: {user.get('team', '')} / {user.get('name', '')} / {user.get('email', '')}",
|
| 3012 |
-
gr.update(visible=True),
|
| 3013 |
-
gr.update(visible=True),
|
| 3014 |
-
gr.update(visible=is_admin_user(user)),
|
| 3015 |
-
)
|
| 3016 |
-
|
| 3017 |
|
| 3018 |
-
|
| 3019 |
-
if not is_approved_user(user):
|
| 3020 |
-
return ""
|
| 3021 |
|
| 3022 |
-
return json.dumps(
|
| 3023 |
-
{
|
| 3024 |
-
"email": user.get("email", ""),
|
| 3025 |
-
"name": user.get("name", ""),
|
| 3026 |
-
"team": user.get("team", ""),
|
| 3027 |
-
"role": user.get("role", ""),
|
| 3028 |
-
"status": user.get("status", ""),
|
| 3029 |
-
},
|
| 3030 |
-
ensure_ascii=False,
|
| 3031 |
-
)
|
| 3032 |
|
| 3033 |
|
|
|
|
|
|
|
|
|
|
| 3034 |
|
| 3035 |
-
def
|
| 3036 |
-
|
| 3037 |
-
return (
|
| 3038 |
-
user,
|
| 3039 |
-
message,
|
| 3040 |
-
screening_update,
|
| 3041 |
-
single_update,
|
| 3042 |
-
admin_update,
|
| 3043 |
-
user_to_session_json(user),
|
| 3044 |
-
)
|
| 3045 |
|
| 3046 |
|
| 3047 |
-
def
|
| 3048 |
-
|
| 3049 |
-
|
| 3050 |
-
|
| 3051 |
-
|
| 3052 |
-
|
| 3053 |
-
|
| 3054 |
-
admin_update,
|
| 3055 |
-
"",
|
| 3056 |
)
|
| 3057 |
|
| 3058 |
|
| 3059 |
|
| 3060 |
-
init_user_db()
|
| 3061 |
-
|
| 3062 |
-
|
| 3063 |
-
|
| 3064 |
# ============================================================
|
| 3065 |
# ๋ก๊ทธ์ธ ์ธ์ฆ
|
| 3066 |
# - Gradio ๊ธฐ๋ณธ ๋ก๊ทธ์ธ์ฐฝ ์ฌ์ฉ
|
|
@@ -3069,6 +2727,8 @@ init_user_db()
|
|
| 3069 |
|
| 3070 |
USER_DB = {
|
| 3071 |
"jin2li@rebom.kr": "qwer0515!",
|
|
|
|
|
|
|
| 3072 |
|
| 3073 |
# ์ฌ์ฉ์ ์ถ๊ฐ ์์:
|
| 3074 |
# "yubin.p@rebom.kr": "์ํ๋๋น๋ฐ๋ฒํธ",
|
|
@@ -3079,15 +2739,9 @@ USER_DB = {
|
|
| 3079 |
def auth_fn(username, password):
|
| 3080 |
username = str(username).strip().lower()
|
| 3081 |
password = str(password).strip()
|
| 3082 |
-
|
| 3083 |
return USER_DB.get(username) == password
|
| 3084 |
|
| 3085 |
|
| 3086 |
-
|
| 3087 |
-
# ============================================================
|
| 3088 |
-
# Gradio ๊ธฐ๋ณธ auth ์ฌ์ฉ ์ ๋ด๋ถ ๋ก๊ทธ์ธ ์ฒดํฌ ์ฐํ
|
| 3089 |
-
# ============================================================
|
| 3090 |
-
|
| 3091 |
def process_with_auth(user, countries, file, product_name="", use_mfds_live=False, live_max_terms=30, live_headless=True):
|
| 3092 |
return process(countries, file, product_name, use_mfds_live, live_max_terms, live_headless)
|
| 3093 |
|
|
@@ -3106,14 +2760,18 @@ def process_single_ingredient_with_auth(user, countries, single_query, single_am
|
|
| 3106 |
# ============================================================
|
| 3107 |
# ๋ก๊ทธ์ธ ์ธ์ฆ
|
| 3108 |
# - Gradio ๊ธฐ๋ณธ ๋ก๊ทธ์ธ์ฐฝ ์ฌ์ฉ
|
| 3109 |
-
# - USER_DB์
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3110 |
# ============================================================
|
| 3111 |
|
| 3112 |
USER_DB = {
|
| 3113 |
"jin2li@rebom.kr": "qwer0515!",
|
| 3114 |
|
| 3115 |
-
# ์ฌ์ฉ์
|
| 3116 |
-
# "yubin.p@rebom.kr": "
|
| 3117 |
# "jkh@rebom.kr": "rebom123!",
|
| 3118 |
}
|
| 3119 |
|
|
@@ -3124,6 +2782,7 @@ def auth_fn(username, password):
|
|
| 3124 |
return USER_DB.get(username) == password
|
| 3125 |
|
| 3126 |
|
|
|
|
| 3127 |
def process_with_auth(user, countries, file, product_name="", use_mfds_live=False, live_max_terms=30, live_headless=True):
|
| 3128 |
return process(countries, file, product_name, use_mfds_live, live_max_terms, live_headless)
|
| 3129 |
|
|
@@ -3144,10 +2803,6 @@ def process_single_ingredient_with_auth(user, countries, single_query, single_am
|
|
| 3144 |
# - Gradio ๊ธฐ๋ณธ ๋ก๊ทธ์ธ์ฐฝ ์ฌ์ฉ
|
| 3145 |
# - ์๋ USER_DB์ ๋ฉ์ผ/๋น๋ฐ๋ฒํธ๋ฅผ ์ง์ ๋ฑ๋ก
|
| 3146 |
# ============================================================
|
| 3147 |
-
# ์ฌ์ฉ์ ์ถ๊ฐ ๋ฐฉ๋ฒ:
|
| 3148 |
-
# USER_DB ์์ ์๋ ํ์์ผ๋ก ํ ์ค์ฉ ์ถ๊ฐํ์ธ์.
|
| 3149 |
-
# "๋ฉ์ผ์ฃผ์": "๋น๋ฐ๋ฒํธ",
|
| 3150 |
-
# ============================================================
|
| 3151 |
|
| 3152 |
USER_DB = {
|
| 3153 |
"jin2li@rebom.kr": "qwer0515!",
|
|
@@ -3164,7 +2819,6 @@ def auth_fn(username, password):
|
|
| 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 |
|
|
@@ -3416,7 +3070,6 @@ with gr.Blocks(css=custom_css) as demo:
|
|
| 3416 |
|
| 3417 |
with gr.Tab("๐ ์คํฌ๋ฆฌ๋", visible=True) as screening_tab:
|
| 3418 |
gr.Markdown("## ๐ ์ ์ฑ๋ถ ์คํฌ๋ฆฌ๋")
|
| 3419 |
-
gr.Markdown("๋ก๊ทธ์ธ ๋ฐ ๊ด๋ฆฌ์ ์น์ธ ์๋ฃ ํ ์ฌ์ฉํ ์ ์์ต๋๋ค.")
|
| 3420 |
|
| 3421 |
country=gr.CheckboxGroup(choices=get_country_folders(),value=[],label="๐ ๊ตญ๊ฐ / ์ฑ๋ ์ ํ",elem_id="country_checks")
|
| 3422 |
refresh=gr.Button("๐ ํด๋/๊ท์ ํ์ผ ์๋ก๊ณ ์นจ")
|
|
@@ -3441,7 +3094,6 @@ with gr.Blocks(css=custom_css) as demo:
|
|
| 3441 |
|
| 3442 |
with gr.Tab("๐ ๋จ์ผ ์ฑ๋ถ ๊ฒ์", visible=True) as single_tab:
|
| 3443 |
gr.Markdown("## ๐ ๋จ์ผ ์ฑ๋ถ ๊ฒ์")
|
| 3444 |
-
gr.Markdown("๋ก๊ทธ์ธ ๋ฐ ๊ด๋ฆฌ์ ์น์ธ ์๋ฃ ํ ์ฌ์ฉํ ์ ์์ต๋๋ค.")
|
| 3445 |
|
| 3446 |
single_country=gr.CheckboxGroup(choices=get_country_folders(),value=[],label="๐ ๊ฒ์ ๊ตญ๊ฐ / ์ฑ๋ ์ ํ",elem_id="single_country_checks")
|
| 3447 |
single_refresh=gr.Button("๐ ๊ตญ๊ฐ/๊ท์ ํ์ผ ์๋ก๊ณ ์นจ")
|
|
@@ -3462,9 +3114,6 @@ with gr.Blocks(css=custom_css) as demo:
|
|
| 3462 |
outputs=[single_df_out,single_msg_out],
|
| 3463 |
)
|
| 3464 |
|
| 3465 |
-
with gr.Tab("๐ ํ์ ์น์ธ ๊ด๋ฆฌ") as admin_tab:
|
| 3466 |
-
gr.Markdown("## ๐ ํ์ ์น์ธ ๊ด๋ฆฌ")
|
| 3467 |
-
gr.Markdown("๊ด๋ฆฌ์ ๊ณ์ ์ผ๋ก ๋ก๊ทธ์ธํ ๊ฒฝ์ฐ์๋ง ์น์ธ/๊ฑฐ์ ํ ์ ์์ต๋๋ค.")
|
| 3468 |
|
| 3469 |
user_filter = gr.Dropdown(
|
| 3470 |
choices=["pending", "approved", "rejected", "์ ์ฒด"],
|
|
@@ -3476,8 +3125,6 @@ with gr.Blocks(css=custom_css) as demo:
|
|
| 3476 |
target_email = gr.Textbox(label="์ ํํ ํ์ ๋ฉ์ผ ์ฃผ์", placeholder="ํ์ ๋ชฉ๋ก์์ ํ์ ํด๋ฆญํ๊ฑฐ๋ ๋ฉ์ผ ์ฃผ์๋ฅผ ์ง์ ์
๋ ฅ")
|
| 3477 |
|
| 3478 |
with gr.Row():
|
| 3479 |
-
approve_btn = gr.Button("์น์ธ", variant="primary")
|
| 3480 |
-
reject_btn = gr.Button("๊ฑฐ์ ", variant="stop")
|
| 3481 |
delete_btn = gr.Button("์ญ์ ", variant="stop")
|
| 3482 |
|
| 3483 |
admin_status = gr.Textbox(label="๊ด๋ฆฌ์ ์ฒ๋ฆฌ ์ํ", interactive=False, lines=4)
|
|
|
|
| 2623 |
return secrets.compare_digest(check, digest)
|
| 2624 |
|
| 2625 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2626 |
def logout_user():
|
| 2627 |
return {}, "๐ช ๋ก๊ทธ์์๋์์ต๋๋ค."
|
| 2628 |
|
|
|
|
| 2671 |
)
|
| 2672 |
|
| 2673 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2674 |
def pick_user_email_from_table(evt):
|
| 2675 |
"""
|
| 2676 |
ํ์ ๋ชฉ๋ก ํ์์ ํ์ ํด๋ฆญํ๋ฉด ํด๋น ํ์ email์ ์น์ธ/๊ฑฐ์ /์ญ์ ์
๋ ฅ์นธ์ ์๋ ์
๋ ฅํ๋ค.
|
|
|
|
| 2692 |
return ""
|
| 2693 |
|
| 2694 |
|
| 2695 |
+
def auth_fn(username, password):
|
| 2696 |
+
username = str(username).strip().lower()
|
| 2697 |
+
password = str(password).strip()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2698 |
|
| 2699 |
+
return USER_DB.get(username) == password
|
|
|
|
|
|
|
| 2700 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2701 |
|
| 2702 |
|
| 2703 |
+
# ============================================================
|
| 2704 |
+
# Gradio ๊ธฐ๋ณธ auth ์ฌ์ฉ ์ ๋ด๋ถ ๋ก๊ทธ์ธ ์ฒดํฌ ์ฐํ
|
| 2705 |
+
# ============================================================
|
| 2706 |
|
| 2707 |
+
def process_with_auth(user, countries, file, product_name="", use_mfds_live=False, live_max_terms=30, live_headless=True):
|
| 2708 |
+
return process(countries, file, product_name, use_mfds_live, live_max_terms, live_headless)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2709 |
|
| 2710 |
|
| 2711 |
+
def process_single_ingredient_with_auth(user, countries, single_query, single_amount, single_function, single_use_mfds_live=False):
|
| 2712 |
+
return process_single_ingredient(
|
| 2713 |
+
countries,
|
| 2714 |
+
single_query,
|
| 2715 |
+
single_amount,
|
| 2716 |
+
single_function,
|
| 2717 |
+
single_use_mfds_live,
|
|
|
|
|
|
|
| 2718 |
)
|
| 2719 |
|
| 2720 |
|
| 2721 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2722 |
# ============================================================
|
| 2723 |
# ๋ก๊ทธ์ธ ์ธ์ฆ
|
| 2724 |
# - Gradio ๊ธฐ๋ณธ ๋ก๊ทธ์ธ์ฐฝ ์ฌ์ฉ
|
|
|
|
| 2727 |
|
| 2728 |
USER_DB = {
|
| 2729 |
"jin2li@rebom.kr": "qwer0515!",
|
| 2730 |
+
"jkh@rebom.kr": "rebom123!"
|
| 2731 |
+
"admin : rebom123!"
|
| 2732 |
|
| 2733 |
# ์ฌ์ฉ์ ์ถ๊ฐ ์์:
|
| 2734 |
# "yubin.p@rebom.kr": "์ํ๋๋น๋ฐ๋ฒํธ",
|
|
|
|
| 2739 |
def auth_fn(username, password):
|
| 2740 |
username = str(username).strip().lower()
|
| 2741 |
password = str(password).strip()
|
|
|
|
| 2742 |
return USER_DB.get(username) == password
|
| 2743 |
|
| 2744 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2745 |
def process_with_auth(user, countries, file, product_name="", use_mfds_live=False, live_max_terms=30, live_headless=True):
|
| 2746 |
return process(countries, file, product_name, use_mfds_live, live_max_terms, live_headless)
|
| 2747 |
|
|
|
|
| 2760 |
# ============================================================
|
| 2761 |
# ๋ก๊ทธ์ธ ์ธ์ฆ
|
| 2762 |
# - Gradio ๊ธฐ๋ณธ ๋ก๊ทธ์ธ์ฐฝ ์ฌ์ฉ
|
| 2763 |
+
# - ์๋ USER_DB์ ๋ฉ์ผ/๋น๋ฐ๋ฒํธ๋ฅผ ์ง์ ๋ฑ๋ก
|
| 2764 |
+
# ============================================================
|
| 2765 |
+
# ์ฌ์ฉ์ ์ถ๊ฐ ๋ฐฉ๋ฒ:
|
| 2766 |
+
# USER_DB ์์ ์๋ ํ์์ผ๋ก ํ ์ค์ฉ ์ถ๊ฐํ์ธ์.
|
| 2767 |
+
# "๋ฉ์ผ์ฃผ์": "๋น๋ฐ๋ฒํธ",
|
| 2768 |
# ============================================================
|
| 2769 |
|
| 2770 |
USER_DB = {
|
| 2771 |
"jin2li@rebom.kr": "qwer0515!",
|
| 2772 |
|
| 2773 |
+
# ์ฌ์ฉ์ ๋ฑ๋ก ์์:
|
| 2774 |
+
# "yubin.p@rebom.kr": "123456!",
|
| 2775 |
# "jkh@rebom.kr": "rebom123!",
|
| 2776 |
}
|
| 2777 |
|
|
|
|
| 2782 |
return USER_DB.get(username) == password
|
| 2783 |
|
| 2784 |
|
| 2785 |
+
# Gradio ๊ธฐ๋ณธ auth๋ฅผ ํต๊ณผํ ์ฌ์ฉ์๋ ์ด๋ฏธ ์ธ์ฆ๋ ์ํ์ด๋ฏ๋ก ๋ด๋ถ ๋ก๊ทธ์ธ ์ฒดํฌ๋ฅผ ํ์ง ์๋๋ค.
|
| 2786 |
def process_with_auth(user, countries, file, product_name="", use_mfds_live=False, live_max_terms=30, live_headless=True):
|
| 2787 |
return process(countries, file, product_name, use_mfds_live, live_max_terms, live_headless)
|
| 2788 |
|
|
|
|
| 2803 |
# - Gradio ๊ธฐ๋ณธ ๋ก๊ทธ์ธ์ฐฝ ์ฌ์ฉ
|
| 2804 |
# - ์๋ USER_DB์ ๋ฉ์ผ/๋น๋ฐ๋ฒํธ๋ฅผ ์ง์ ๋ฑ๋ก
|
| 2805 |
# ============================================================
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2806 |
|
| 2807 |
USER_DB = {
|
| 2808 |
"jin2li@rebom.kr": "qwer0515!",
|
|
|
|
| 2819 |
return USER_DB.get(username) == password
|
| 2820 |
|
| 2821 |
|
|
|
|
| 2822 |
def process_with_auth(user, countries, file, product_name="", use_mfds_live=False, live_max_terms=30, live_headless=True):
|
| 2823 |
return process(countries, file, product_name, use_mfds_live, live_max_terms, live_headless)
|
| 2824 |
|
|
|
|
| 3070 |
|
| 3071 |
with gr.Tab("๐ ์คํฌ๋ฆฌ๋", visible=True) as screening_tab:
|
| 3072 |
gr.Markdown("## ๐ ์ ์ฑ๋ถ ์คํฌ๋ฆฌ๋")
|
|
|
|
| 3073 |
|
| 3074 |
country=gr.CheckboxGroup(choices=get_country_folders(),value=[],label="๐ ๊ตญ๊ฐ / ์ฑ๋ ์ ํ",elem_id="country_checks")
|
| 3075 |
refresh=gr.Button("๐ ํด๋/๊ท์ ํ์ผ ์๋ก๊ณ ์นจ")
|
|
|
|
| 3094 |
|
| 3095 |
with gr.Tab("๐ ๋จ์ผ ์ฑ๋ถ ๊ฒ์", visible=True) as single_tab:
|
| 3096 |
gr.Markdown("## ๐ ๋จ์ผ ์ฑ๋ถ ๊ฒ์")
|
|
|
|
| 3097 |
|
| 3098 |
single_country=gr.CheckboxGroup(choices=get_country_folders(),value=[],label="๐ ๊ฒ์ ๊ตญ๊ฐ / ์ฑ๋ ์ ํ",elem_id="single_country_checks")
|
| 3099 |
single_refresh=gr.Button("๐ ๊ตญ๊ฐ/๊ท์ ํ์ผ ์๋ก๊ณ ์นจ")
|
|
|
|
| 3114 |
outputs=[single_df_out,single_msg_out],
|
| 3115 |
)
|
| 3116 |
|
|
|
|
|
|
|
|
|
|
| 3117 |
|
| 3118 |
user_filter = gr.Dropdown(
|
| 3119 |
choices=["pending", "approved", "rejected", "์ ์ฒด"],
|
|
|
|
| 3125 |
target_email = gr.Textbox(label="์ ํํ ํ์ ๋ฉ์ผ ์ฃผ์", placeholder="ํ์ ๋ชฉ๋ก์์ ํ์ ํด๋ฆญํ๊ฑฐ๋ ๋ฉ์ผ ์ฃผ์๋ฅผ ์ง์ ์
๋ ฅ")
|
| 3126 |
|
| 3127 |
with gr.Row():
|
|
|
|
|
|
|
| 3128 |
delete_btn = gr.Button("์ญ์ ", variant="stop")
|
| 3129 |
|
| 3130 |
admin_status = gr.Textbox(label="๊ด๋ฆฌ์ ์ฒ๋ฆฌ ์ํ", interactive=False, lines=4)
|