huy00001 commited on
Commit
8bd49c3
·
1 Parent(s): 2d42968
Files changed (2) hide show
  1. app.py +35 -0
  2. requirements.txt +5 -0
app.py ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from deepface import DeepFace
3
+ import json
4
+
5
+ def analyze_image(image):
6
+ try:
7
+ # Phân tích ảnh
8
+ result = DeepFace.analyze(
9
+ img_path=image,
10
+ actions=["age", "gender", "emotion", "race"],
11
+ enforce_detection=False
12
+ )
13
+ info = result[0]
14
+ output = {
15
+ "Tuổi ước tính": info["age"],
16
+ "Giới tính": "Nam" if info["dominant_gender"] == "Man" else "Nữ",
17
+ "Cảm xúc chính": info["dominant_emotion"],
18
+ "Chủng tộc": info["dominant_race"],
19
+ "Độ tin cậy": round(info["face_confidence"], 2)
20
+ }
21
+ return json.dumps(output, ensure_ascii=False, indent=2)
22
+ except Exception as e:
23
+ return f"Lỗi: {str(e)}"
24
+
25
+ # Tạo giao diện Gradio
26
+ demo = gr.Interface(
27
+ fn=analyze_image,
28
+ inputs=gr.Image(type="numpy", label="📸 Tải ảnh khuôn mặt của bạn"),
29
+ outputs=gr.Textbox(label="Kết quả phân tích"),
30
+ title="Phân tích khuôn mặt với DeepFace",
31
+ description="Upload ảnh để nhận diện tuổi, giới tính, cảm xúc và chủng tộc."
32
+ )
33
+
34
+ if __name__ == "__main__":
35
+ demo.launch()
requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ gradio>=3.39
2
+ deepface
3
+ opencv-python
4
+ tensorflow
5
+