-
Notifications
You must be signed in to change notification settings - Fork 53
Expand file tree
/
Copy pathfrontend.py
More file actions
85 lines (63 loc) · 2.73 KB
/
frontend.py
File metadata and controls
85 lines (63 loc) · 2.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import requests
import streamlit as st
API_URL = "http://localhost:8000"
st.set_page_config(page_title="얼굴 인식 회원 관리 시스템")
st.title("얼굴 인식 회원 관리 시스템 🚀")
menu = st.sidebar.selectbox(
"기능 선택", ["회원 등록", "회원 인증", "회원 조회", "회원 삭제"]
)
if menu == "회원 등록":
st.subheader("📝 회원 등록")
user_id = st.text_input("사용자 ID")
image = st.file_uploader("얼굴 이미지 업로드", type=["jpg", "jpeg", "png"])
if st.button("등록하기"):
if user_id and image:
files = {"image": (image.name, image.getvalue(), image.type)}
data = {"user_id": user_id}
res = requests.post(f"{API_URL}/users/register", data=data, files=files)
if res.status_code == 200:
st.success(f"등록 성공: {res.json()}")
else:
st.error(f"등록 실패: {res.json().get('detail')}")
else:
st.warning("ID와 이미지를 모두 입력해주세요.")
elif menu == "회원 인증":
st.subheader("🔑 회원 인증")
image = st.file_uploader(
"인증할 얼굴 이미지 업로드", type=["jpg", "jpeg", "png"], key="auth"
)
if st.button("인증하기"):
if image:
files = {"image": (image.name, image.getvalue(), image.type)}
res = requests.post(f"{API_URL}/users/authenticate", files=files)
if res.status_code == 200:
st.success(f"인증 성공! 사용자 ID: {res.json()['user_id']}")
else:
st.error(f"인증 실패: {res.json().get('detail')}")
else:
st.warning("이미지를 업로드해주세요.")
elif menu == "회원 조회":
st.subheader("🔍 회원 조회")
user_id = st.text_input("조회할 사용자 ID")
if st.button("조회하기"):
if user_id:
res = requests.get(f"{API_URL}/users/{user_id}")
if res.status_code == 200:
user_info = res.json()
st.json(user_info)
else:
st.error(f"조회 실패: {res.json().get('detail')}")
else:
st.warning("사용자 ID를 입력해주세요.")
elif menu == "회원 삭제":
st.subheader("🗑️ 회원 삭제")
user_id = st.text_input("삭제할 사용자 ID")
if st.button("삭제하기"):
if user_id:
res = requests.delete(f"{API_URL}/users/{user_id}")
if res.status_code == 200:
st.success("성공적으로 삭제되었습니다.")
else:
st.error(f"삭제 실패: {res.json().get('detail')}")
else:
st.warning("사용자 ID를 입력해주세요.")