Prince-1 commited on
Commit
4649692
Β·
verified Β·
1 Parent(s): 6b0e363

Upload 2 files

Browse files
Files changed (2) hide show
  1. pyproject.toml +19 -0
  2. src/streamlit_app.py +152 -110
pyproject.toml ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [project]
2
+ name = "parentclosetesting"
3
+ version = "0.1.0"
4
+ description = "Add your description here"
5
+ readme = "README.md"
6
+ requires-python = ">=3.13"
7
+ dependencies = [
8
+ "deepface>=0.0.100",
9
+ "insightface>=1.0.1",
10
+ "numpy>=2.5.0",
11
+ "onnxruntime>=1.27.0",
12
+ "opencv-python-headless>=4.13.0.92",
13
+ "pillow>=12.2.0",
14
+ "streamlit>=1.58.0",
15
+ "tf-keras>=2.21.0",
16
+ "torch>=2.12.1",
17
+ "torchvision>=0.27.1",
18
+ "transformers>=5.12.1",
19
+ ]
src/streamlit_app.py CHANGED
@@ -1,110 +1,152 @@
1
- import sys
2
- import os
3
- import tempfile
4
-
5
- import streamlit as st
6
-
7
- sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
8
-
9
- st.set_page_config(
10
- page_title="More Close To Whom?",
11
- page_icon="πŸ‘¨β€πŸ‘©β€πŸ‘§",
12
- layout="wide",
13
- )
14
-
15
- st.title("πŸ‘¨β€πŸ‘©β€πŸ‘§ More Close To Whom?")
16
- st.caption("Upload photos of father, mother, and child to discover who the child resembles more")
17
-
18
- # Backend selector
19
- backend_choice = st.radio(
20
- "ML Backend",
21
- ["🧠 DeepFace", "⚑ InsightFace", "πŸ€— HF Model"],
22
- horizontal=True,
23
- help="Select the AI model to use for face analysis",
24
- )
25
-
26
- st.divider()
27
-
28
- # Upload row: Father | Child (center, wider) | Mother
29
- col_f, col_c, col_m = st.columns([1, 1.3, 1])
30
-
31
- with col_f:
32
- st.markdown("#### πŸ‘¨ Father")
33
- father_file = st.file_uploader(
34
- "Upload father photo", type=["jpg", "jpeg", "png"], key="father", label_visibility="collapsed"
35
- )
36
- if father_file:
37
- st.image(father_file, use_container_width=True)
38
-
39
- with col_c:
40
- st.markdown("#### πŸ§’ Child")
41
- child_file = st.file_uploader(
42
- "Upload child photo", type=["jpg", "jpeg", "png"], key="child", label_visibility="collapsed"
43
- )
44
- if child_file:
45
- st.image(child_file, use_container_width=True)
46
-
47
- with col_m:
48
- st.markdown("#### πŸ‘© Mother")
49
- mother_file = st.file_uploader(
50
- "Upload mother photo", type=["jpg", "jpeg", "png"], key="mother", label_visibility="collapsed"
51
- )
52
- if mother_file:
53
- st.image(mother_file, use_container_width=True)
54
-
55
- st.divider()
56
-
57
- all_uploaded = all([father_file, child_file, mother_file])
58
-
59
- if st.button("β–Ά Analyze Resemblance", type="primary", disabled=not all_uploaded):
60
- with st.spinner("Analyzing faces β€” this may take a moment on first run..."):
61
- with tempfile.TemporaryDirectory() as tmpdir:
62
- def save(uploaded, name):
63
- path = os.path.join(tmpdir, name)
64
- with open(path, "wb") as f:
65
- f.write(uploaded.getvalue())
66
- return path
67
-
68
- father_path = save(father_file, "father.jpg")
69
- mother_path = save(mother_file, "mother.jpg")
70
- child_path = save(child_file, "child.jpg")
71
-
72
- try:
73
- if "DeepFace" in backend_choice:
74
- from backends.deepface_backend import analyze
75
- elif "InsightFace" in backend_choice:
76
- from backends.insightface_backend import analyze
77
- else:
78
- from backends.hf_backend import analyze
79
-
80
- result = analyze(father_path, mother_path, child_path)
81
-
82
- st.success("Analysis complete!")
83
-
84
- r1, r2, r3 = st.columns(3)
85
- with r1:
86
- st.metric("πŸ‘¨ Father resemblance", f"{result['father_score']}%")
87
- st.progress(result["father_score"] / 100)
88
- with r2:
89
- st.metric("πŸ‘© Mother resemblance", f"{result['mother_score']}%")
90
- st.progress(result["mother_score"] / 100)
91
- with r3:
92
- st.metric("πŸ§’ Estimated child age", f"{result['age']} yrs")
93
-
94
- st.divider()
95
-
96
- diff = abs(result["father_score"] - result["mother_score"])
97
- if diff < 2:
98
- st.info("βš–οΈ Child resembles both parents almost equally!")
99
- elif result["father_score"] >= result["mother_score"]:
100
- st.success(f"βœ… Child looks more like **Father πŸ‘¨** ({diff:.1f}% difference)")
101
- else:
102
- st.success(f"βœ… Child looks more like **Mother πŸ‘©** ({diff:.1f}% difference)")
103
-
104
- except ValueError as e:
105
- st.error(f"⚠️ {e}")
106
- except Exception as e:
107
- st.error(f"❌ Analysis failed: {e}")
108
-
109
- elif not all_uploaded:
110
- st.info("πŸ‘† Please upload photos of all three family members to begin")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import sys
2
+ import os
3
+ import tempfile
4
+
5
+ import streamlit as st
6
+
7
+ sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
8
+
9
+ st.set_page_config(
10
+ page_title="More Close To Whom?",
11
+ page_icon="πŸ‘¨β€πŸ‘©β€πŸ‘§",
12
+ layout="wide",
13
+ )
14
+
15
+ st.title("πŸ‘¨β€πŸ‘©β€πŸ‘§ More Close To Whom?")
16
+ st.caption("Upload photos of father, mother, and child to discover who the child resembles more")
17
+
18
+ # Backend selector
19
+ backend_choice = st.radio(
20
+ "ML Backend",
21
+ ["🧠 DeepFace", "⚑ InsightFace", "πŸ€— HF Model"],
22
+ horizontal=True,
23
+ help="Select the AI model to use for face analysis",
24
+ )
25
+
26
+ st.divider()
27
+
28
+ # Upload row: Father | Child (center, wider) | Mother
29
+ col_f, col_c, col_m = st.columns([1, 1.3, 1])
30
+
31
+ with col_f:
32
+ st.markdown("#### πŸ‘¨ Father")
33
+ tab1, tab2 = st.tabs(["πŸ“ Upload", "πŸ“· Camera"])
34
+ with tab1:
35
+ upload = st.file_uploader(
36
+ "Upload Father Image",
37
+ type=["jpg", "jpeg", "png","webp"],
38
+ key="father_upload",
39
+ label_visibility="collapsed",
40
+ )
41
+
42
+ with tab2:
43
+ camera = st.camera_input(
44
+ "Capture Father Image",
45
+ key="father_camera",
46
+ label_visibility="collapsed",
47
+ )
48
+
49
+ father_file = camera if camera else upload
50
+ if father_file:
51
+ st.image(father_file, use_container_width=True)
52
+
53
+ with col_c:
54
+ st.markdown("#### πŸ§’ Child")
55
+ tab1, tab2 = st.tabs(["πŸ“ Upload", "πŸ“· Camera"])
56
+ with tab1:
57
+ upload = st.file_uploader(
58
+ "Upload child photo",
59
+ type=["jpg", "jpeg", "png","webp"],
60
+ key="child_upload",
61
+ label_visibility="collapsed",
62
+ )
63
+
64
+ with tab2:
65
+ camera = st.camera_input(
66
+ "Capture child photo",
67
+ key="child_camera",
68
+ label_visibility="collapsed",
69
+ )
70
+
71
+ child_file = camera if camera else upload
72
+ if child_file:
73
+ st.image(child_file, use_container_width=True)
74
+
75
+ with col_m:
76
+ st.markdown("#### πŸ‘© Mother")
77
+ tab1, tab2 = st.tabs(["πŸ“ Upload", "πŸ“· Camera"])
78
+ with tab1:
79
+ upload = st.file_uploader(
80
+ "Upload mother photo",
81
+ type=["jpg", "jpeg", "png","webp"],
82
+ key="mother_upload",
83
+ label_visibility="collapsed",
84
+ )
85
+
86
+ with tab2:
87
+ camera = st.camera_input(
88
+ "Capture mother photo",
89
+ key="mother_camera",
90
+ label_visibility="collapsed",
91
+ )
92
+
93
+ mother_file = camera if camera else upload
94
+ if mother_file:
95
+ st.image(mother_file, use_container_width=True)
96
+
97
+ st.divider()
98
+
99
+ all_uploaded = all([father_file, child_file, mother_file])
100
+
101
+ if st.button("β–Ά Analyze Resemblance", type="primary", disabled=not all_uploaded):
102
+ with st.spinner("Analyzing faces β€” this may take a moment on first run..."):
103
+ with tempfile.TemporaryDirectory() as tmpdir:
104
+ def save(uploaded, name):
105
+ path = os.path.join(tmpdir, name)
106
+ with open(path, "wb") as f:
107
+ f.write(uploaded.getvalue())
108
+ return path
109
+
110
+ father_path = save(father_file, "father.jpg")
111
+ mother_path = save(mother_file, "mother.jpg")
112
+ child_path = save(child_file, "child.jpg")
113
+
114
+ try:
115
+ if "DeepFace" in backend_choice:
116
+ from backends.deepface_backend import analyze
117
+ elif "InsightFace" in backend_choice:
118
+ from backends.insightface_backend import analyze
119
+ else:
120
+ from backends.hf_backend import analyze
121
+
122
+ result = analyze(father_path, mother_path, child_path)
123
+
124
+ st.success("Analysis complete!")
125
+
126
+ r1, r2, r3 = st.columns(3)
127
+ with r1:
128
+ st.metric("πŸ‘¨ Father resemblance", f"{result['father_score']}%")
129
+ st.progress(result["father_score"] / 100)
130
+ with r2:
131
+ st.metric("πŸ‘© Mother resemblance", f"{result['mother_score']}%")
132
+ st.progress(result["mother_score"] / 100)
133
+ with r3:
134
+ st.metric("πŸ§’ Estimated child age", f"{result['age']} yrs")
135
+
136
+ st.divider()
137
+
138
+ diff = abs(result["father_score"] - result["mother_score"])
139
+ if diff < 2:
140
+ st.info("βš–οΈ Child resembles both parents almost equally!")
141
+ elif result["father_score"] >= result["mother_score"]:
142
+ st.success(f"βœ… Child looks more like **Father πŸ‘¨** ({diff:.1f}% difference)")
143
+ else:
144
+ st.success(f"βœ… Child looks more like **Mother πŸ‘©** ({diff:.1f}% difference)")
145
+
146
+ except ValueError as e:
147
+ st.error(f"⚠️ {e}")
148
+ except Exception as e:
149
+ st.error(f"❌ Analysis failed: {e}")
150
+
151
+ elif not all_uploaded:
152
+ st.info("πŸ‘† Please upload photos of all three family members to begin")