Update app.py
Browse files
app.py
CHANGED
|
@@ -29,14 +29,10 @@ theme = gr.themes.Soft(
|
|
| 29 |
input_border_color_dark="#555555",
|
| 30 |
button_primary_background_fill="#1e40af",
|
| 31 |
button_primary_background_fill_hover="#2563eb",
|
| 32 |
-
button_primary_text_color="#
|
| 33 |
button_secondary_background_fill="#404040",
|
| 34 |
button_secondary_background_fill_hover="#555555",
|
| 35 |
-
button_secondary_text_color="#
|
| 36 |
-
block_label_text_color="#e5e5e5",
|
| 37 |
-
block_title_text_color="#e5e5e5",
|
| 38 |
-
input_text_color="#e5e5e5",
|
| 39 |
-
input_placeholder_color="#e5e5e5"
|
| 40 |
)
|
| 41 |
|
| 42 |
def normalize_url(url: str) -> str:
|
|
@@ -152,7 +148,7 @@ def search_contacts(url: str) -> tuple[str, str]:
|
|
| 152 |
"""
|
| 153 |
|
| 154 |
if not url.strip():
|
| 155 |
-
return "Please enter a website URL", ""
|
| 156 |
|
| 157 |
# Clean and validate URL
|
| 158 |
url = url.strip()
|
|
@@ -191,10 +187,10 @@ def search_contacts(url: str) -> tuple[str, str]:
|
|
| 191 |
# If we filtered out everything or got very few results compared to original,
|
| 192 |
# it's likely the API returned all contacts instead of URL-specific ones
|
| 193 |
if len(filtered_result) == 0:
|
| 194 |
-
return f"No contacts found for: {original_url}\n\nThis URL may not be in our database.", json.dumps(result, indent=2)
|
| 195 |
elif original_count > 50 and len(filtered_result) < 5:
|
| 196 |
# Likely got all contacts, filtered to very few - show warning
|
| 197 |
-
formatted_output = f"**Warning:** API returned {original_count} total contacts. After filtering for '{original_url}', found {len(filtered_result)} matches.\n\n"
|
| 198 |
formatted_output += "These results may not be accurate. The URL might not be in our database.\n\n"
|
| 199 |
formatted_output += format_contact_results(filtered_result, url)
|
| 200 |
else:
|
|
@@ -207,9 +203,9 @@ def search_contacts(url: str) -> tuple[str, str]:
|
|
| 207 |
filtered_contacts = filter_contacts_by_url(actual_result['contacts'], url)
|
| 208 |
|
| 209 |
if len(filtered_contacts) == 0:
|
| 210 |
-
return f"No contacts found for: {original_url}\n\nThis URL may not be in our database.", json.dumps(result, indent=2)
|
| 211 |
elif original_count > 50 and len(filtered_contacts) < 5:
|
| 212 |
-
formatted_output = f"**Warning:** API returned {original_count} total contacts. After filtering for '{original_url}', found {len(filtered_contacts)} matches.\n\n"
|
| 213 |
formatted_output += "These results may not be accurate. The URL might not be in our database.\n\n"
|
| 214 |
formatted_output += format_contact_results({'contacts': filtered_contacts}, url)
|
| 215 |
else:
|
|
@@ -237,17 +233,17 @@ def search_contacts(url: str) -> tuple[str, str]:
|
|
| 237 |
return formatted_output, raw_json
|
| 238 |
|
| 239 |
except json.JSONDecodeError:
|
| 240 |
-
return f"Error: Invalid JSON response from API", response.text
|
| 241 |
|
| 242 |
else:
|
| 243 |
-
return f"API Error ({response.status_code}): {response.text}", ""
|
| 244 |
|
| 245 |
except requests.exceptions.Timeout:
|
| 246 |
-
return "Request timeout. Please try again.", ""
|
| 247 |
except requests.exceptions.ConnectionError:
|
| 248 |
-
return "Connection error. Please check your API endpoint.", ""
|
| 249 |
except Exception as e:
|
| 250 |
-
return f"Error: {str(e)}", ""
|
| 251 |
|
| 252 |
def format_contact_results(results: Dict[Any, Any], url: str) -> str:
|
| 253 |
"""
|
|
|
|
| 29 |
input_border_color_dark="#555555",
|
| 30 |
button_primary_background_fill="#1e40af",
|
| 31 |
button_primary_background_fill_hover="#2563eb",
|
| 32 |
+
button_primary_text_color="#ffffff",
|
| 33 |
button_secondary_background_fill="#404040",
|
| 34 |
button_secondary_background_fill_hover="#555555",
|
| 35 |
+
button_secondary_text_color="#ffffff"
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
)
|
| 37 |
|
| 38 |
def normalize_url(url: 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 |
# 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 |
"""
|