RajaThor commited on
Commit
9dbec5b
·
verified ·
1 Parent(s): 9912115

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -38
app.py CHANGED
@@ -167,23 +167,42 @@ def recognize_face(image_path):
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}"
@@ -194,36 +213,6 @@ def recognize_face(image_path):
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):
 
167
  info = data["info"]
168
  email = info.get("email", "Email not provided")
169
  insta_handle = info["instagram_handle"]
170
+
171
+ # Instagram API request
172
+ url = "https://instagram-scraper-api2.p.rapidapi.com/v1/info"
173
+ querystring = {"username_or_id_or_url": insta_handle}
174
+ headers = {
175
+ "x-rapidapi-key": "bc2b15f577msh345ac5a5b422c7ep106f73jsn580b1c25e0d9",
176
+ "x-rapidapi-host": "instagram-scraper-api2.p.rapidapi.com"
177
+ }
178
+
179
+ try:
180
+ response = requests.get(url, headers=headers, params=querystring)
181
+ response.raise_for_status() # Raise an exception for HTTP errors
182
+ data = response.json().get('data', {})
183
+ full_name = data.get('full_name', 'N/A')
184
+ biography = data.get('biography', 'N/A')
185
+ follower_count = data.get('follower_count', 'N/A')
186
+ following_count = data.get('following_count', 'N/A')
187
+ except requests.exceptions.HTTPError as http_err:
188
+ print(f"HTTP error occurred: {http_err}")
189
+ full_name, biography, follower_count, following_count = 'N/A', 'N/A', 'N/A', 'N/A'
190
+ except Exception as err:
191
+ print(f"Other error occurred: {err}")
192
+ full_name, biography, follower_count, following_count = 'N/A', 'N/A', 'N/A', 'N/A'
193
+
194
+ face_matches.append((name, insta_handle, email, full_name, biography, follower_count, following_count))
195
 
196
  if face_matches:
197
  matches.extend(face_matches)
198
  else:
199
+ matches.append(("Unknown", "Unknown", "Unknown", 'N/A', 'N/A', 'N/A', 'N/A'))
200
 
201
  if matches:
202
  results = []
203
+ for name, insta_handle, email, full_name, biography, follower_count, following_count in matches:
204
  insta_link = f"https://www.instagram.com/{insta_handle}/"
205
  insta_link_html = f'<a href="{insta_link}" target="_blank"><font color="red">{insta_handle}</font></a>'
 
 
 
 
206
  results.append(
207
  f"- It's a picture of {name}! Insta handle: {insta_link_html}, Email: {email}, "
208
  f"Full Name: {full_name}, Biography: {biography}, Followers: {follower_count}, Following: {following_count}"
 
213
  return "Face not found in the database."
214
  except Exception as e:
215
  return f"Failed to recognize face: {str(e)}"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
216
 
217
  # Update recognize_face_optimal function to handle multiple face encodings
218
  def recognize_face_optimal(image_path):