RajaThor commited on
Commit
8667f95
·
verified ·
1 Parent(s): c057122

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +44 -4
app.py CHANGED
@@ -8,6 +8,7 @@ import numpy as np
8
  import cv2
9
  import dlib
10
  from io import BytesIO
 
11
 
12
  # Get the current working directory
13
  current_directory = os.path.dirname(os.path.abspath(__file__))
@@ -165,25 +166,64 @@ def recognize_face(image_path):
165
  if face_recognition.compare_faces([known_encoding], unknown_encoding)[0]:
166
  info = data["info"]
167
  email = info.get("email", "Email not provided")
168
- face_matches.append((name, info["instagram_handle"], email))
 
 
169
 
170
  if face_matches:
171
  matches.extend(face_matches)
172
  else:
173
- matches.append(("Unknown", "Unknown", "Unknown"))
174
 
175
  if matches:
176
  results = []
177
- for name, insta_handle, email in matches:
178
  insta_link = f"https://www.instagram.com/{insta_handle}/"
179
  insta_link_html = f'<a href="{insta_link}" target="_blank"><font color="red">{insta_handle}</font></a>'
180
- results.append(f"- It's a picture of {name}! Insta handle: {insta_link_html}, Email: {email}")
 
 
 
 
 
 
 
181
  log_action(st.session_state.auth_state["user"].email, "Recognized face")
182
  return "\n".join(results)
183
  else:
184
  return "Face not found in the database."
185
  except Exception as e:
186
  return f"Failed to recognize face: {str(e)}"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
187
 
188
  # Update recognize_face_optimal function to handle multiple face encodings
189
  def recognize_face_optimal(image_path):
 
8
  import cv2
9
  import dlib
10
  from io import BytesIO
11
+ import requests
12
 
13
  # Get the current working directory
14
  current_directory = os.path.dirname(os.path.abspath(__file__))
 
166
  if face_recognition.compare_faces([known_encoding], unknown_encoding)[0]:
167
  info = data["info"]
168
  email = info.get("email", "Email not provided")
169
+ insta_handle = info["instagram_handle"]
170
+ insta_info = fetch_instagram_info(insta_handle)
171
+ face_matches.append((name, insta_handle, email, insta_info))
172
 
173
  if face_matches:
174
  matches.extend(face_matches)
175
  else:
176
+ matches.append(("Unknown", "Unknown", "Unknown", {}))
177
 
178
  if matches:
179
  results = []
180
+ for name, insta_handle, email, insta_info in matches:
181
  insta_link = f"https://www.instagram.com/{insta_handle}/"
182
  insta_link_html = f'<a href="{insta_link}" target="_blank"><font color="red">{insta_handle}</font></a>'
183
+ full_name = insta_info.get('full_name', 'N/A')
184
+ biography = insta_info.get('biography', 'N/A')
185
+ follower_count = insta_info.get('follower_count', 'N/A')
186
+ following_count = insta_info.get('following_count', 'N/A')
187
+ results.append(
188
+ f"- It's a picture of {name}! Insta handle: {insta_link_html}, Email: {email}, "
189
+ f"Full Name: {full_name}, Biography: {biography}, Followers: {follower_count}, Following: {following_count}"
190
+ )
191
  log_action(st.session_state.auth_state["user"].email, "Recognized face")
192
  return "\n".join(results)
193
  else:
194
  return "Face not found in the database."
195
  except Exception as e:
196
  return f"Failed to recognize face: {str(e)}"
197
+
198
+ def fetch_instagram_info(insta_handle):
199
+ url = "https://instagram-scraper-api2.p.rapidapi.com/v1/info"
200
+ querystring = {"username_or_id_or_url": insta_handle}
201
+
202
+ headers = {
203
+ "x-rapidapi-key": "bc2b15f577msh345ac5a5b422c7ep106f73jsn580b1c25e0d9",
204
+ "x-rapidapi-host": "instagram-scraper-api2.p.rapidapi.com"
205
+ }
206
+
207
+ response = requests.get(url, headers=headers, params=querystring)
208
+
209
+ if response.status_code == 200:
210
+ data = response.json().get('data', {})
211
+ return {
212
+ 'full_name': data.get('full_name', 'N/A'),
213
+ 'biography': data.get('biography', 'N/A'),
214
+ 'profile_pic_url_hd': data.get('profile_pic_url_hd', 'N/A'),
215
+ 'follower_count': data.get('follower_count', 'N/A'),
216
+ 'following_count': data.get('following_count', 'N/A')
217
+ }
218
+ else:
219
+ return {
220
+ 'full_name': 'N/A',
221
+ 'biography': 'N/A',
222
+ 'profile_pic_url_hd': 'N/A',
223
+ 'follower_count': 'N/A',
224
+ 'following_count': 'N/A'
225
+ }
226
+
227
 
228
  # Update recognize_face_optimal function to handle multiple face encodings
229
  def recognize_face_optimal(image_path):