JayBene1 commited on
Commit
68ab069
·
verified ·
1 Parent(s): bf1d9a4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -10
app.py CHANGED
@@ -148,7 +148,7 @@ def search_contacts(url: str) -> tuple[str, str]:
148
  """
149
 
150
  if not url.strip():
151
- return "❌ Please enter a website URL", ""
152
 
153
  # Clean and validate URL
154
  url = url.strip()
@@ -187,10 +187,10 @@ def search_contacts(url: str) -> tuple[str, str]:
187
  # If we filtered out everything or got very few results compared to original,
188
  # it's likely the API returned all contacts instead of URL-specific ones
189
  if len(filtered_result) == 0:
190
- return f"❌ No contacts found for: {original_url}\n\nThis URL may not be in our database.", json.dumps(result, indent=2)
191
  elif original_count > 50 and len(filtered_result) < 5:
192
  # Likely got all contacts, filtered to very few - show warning
193
- formatted_output = f"⚠️ **Warning:** API returned {original_count} total contacts. After filtering for '{original_url}', found {len(filtered_result)} matches.\n\n"
194
  formatted_output += "These results may not be accurate. The URL might not be in our database.\n\n"
195
  formatted_output += format_contact_results(filtered_result, url)
196
  else:
@@ -203,9 +203,9 @@ def search_contacts(url: str) -> tuple[str, str]:
203
  filtered_contacts = filter_contacts_by_url(actual_result['contacts'], url)
204
 
205
  if len(filtered_contacts) == 0:
206
- return f"❌ No contacts found for: {original_url}\n\nThis URL may not be in our database.", json.dumps(result, indent=2)
207
  elif original_count > 50 and len(filtered_contacts) < 5:
208
- formatted_output = f"⚠️ **Warning:** API returned {original_count} total contacts. After filtering for '{original_url}', found {len(filtered_contacts)} matches.\n\n"
209
  formatted_output += "These results may not be accurate. The URL might not be in our database.\n\n"
210
  formatted_output += format_contact_results({'contacts': filtered_contacts}, url)
211
  else:
@@ -233,17 +233,17 @@ def search_contacts(url: str) -> tuple[str, str]:
233
  return formatted_output, raw_json
234
 
235
  except json.JSONDecodeError:
236
- return f"❌ Error: Invalid JSON response from API", response.text
237
 
238
  else:
239
- return f"❌ API Error ({response.status_code}): {response.text}", ""
240
 
241
  except requests.exceptions.Timeout:
242
- return "❌ Request timeout. Please try again.", ""
243
  except requests.exceptions.ConnectionError:
244
- return "❌ Connection error. Please check your API endpoint.", ""
245
  except Exception as e:
246
- return f"❌ Error: {str(e)}", ""
247
 
248
  def format_contact_results(results: Dict[Any, Any], url: str) -> str:
249
  """
 
148
  """
149
 
150
  if not url.strip():
151
+ return "Please enter a website URL", ""
152
 
153
  # Clean and validate URL
154
  url = url.strip()
 
187
  # If we filtered out everything or got very few results compared to original,
188
  # it's likely the API returned all contacts instead of URL-specific ones
189
  if len(filtered_result) == 0:
190
+ return f"No contacts found for: {original_url}\n\nThis URL may not be in our database.", json.dumps(result, indent=2)
191
  elif original_count > 50 and len(filtered_result) < 5:
192
  # Likely got all contacts, filtered to very few - show warning
193
+ formatted_output = f"**Warning:** API returned {original_count} total contacts. After filtering for '{original_url}', found {len(filtered_result)} matches.\n\n"
194
  formatted_output += "These results may not be accurate. The URL might not be in our database.\n\n"
195
  formatted_output += format_contact_results(filtered_result, url)
196
  else:
 
203
  filtered_contacts = filter_contacts_by_url(actual_result['contacts'], url)
204
 
205
  if len(filtered_contacts) == 0:
206
+ return f"No contacts found for: {original_url}\n\nThis URL may not be in our database.", json.dumps(result, indent=2)
207
  elif original_count > 50 and len(filtered_contacts) < 5:
208
+ formatted_output = f"**Warning:** API returned {original_count} total contacts. After filtering for '{original_url}', found {len(filtered_contacts)} matches.\n\n"
209
  formatted_output += "These results may not be accurate. The URL might not be in our database.\n\n"
210
  formatted_output += format_contact_results({'contacts': filtered_contacts}, url)
211
  else:
 
233
  return formatted_output, raw_json
234
 
235
  except json.JSONDecodeError:
236
+ return f"Error: Invalid JSON response from API", response.text
237
 
238
  else:
239
+ return f"API Error ({response.status_code}): {response.text}", ""
240
 
241
  except requests.exceptions.Timeout:
242
+ return "Request timeout. Please try again.", ""
243
  except requests.exceptions.ConnectionError:
244
+ return "Connection error. Please check your API endpoint.", ""
245
  except Exception as e:
246
+ return f"Error: {str(e)}", ""
247
 
248
  def format_contact_results(results: Dict[Any, Any], url: str) -> str:
249
  """