JayBene1 commited on
Commit
e9ba69b
·
verified ·
1 Parent(s): 0baae1c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +41 -13
app.py CHANGED
@@ -46,10 +46,10 @@ theme = gr.themes.Soft(
46
  # Button colors
47
  button_primary_background_fill="#1e40af",
48
  button_primary_background_fill_hover="#2563eb",
49
- button_primary_text_color="#2d2d2d",
50
  button_secondary_background_fill="#404040",
51
  button_secondary_background_fill_hover="#555555",
52
- button_secondary_text_color="#2d2d2d"
53
  )
54
 
55
  def normalize_url(url: str) -> str:
@@ -165,7 +165,7 @@ def search_contacts(url: str) -> tuple[str, str]:
165
  """
166
 
167
  if not url.strip():
168
- return "Please enter a website URL", ""
169
 
170
  # Clean and validate URL
171
  url = url.strip()
@@ -204,10 +204,10 @@ def search_contacts(url: str) -> tuple[str, str]:
204
  # If we filtered out everything or got very few results compared to original,
205
  # it's likely the API returned all contacts instead of URL-specific ones
206
  if len(filtered_result) == 0:
207
- return f"No contacts found for: {original_url}\n\nThis URL may not be in our database.", json.dumps(result, indent=2)
208
  elif original_count > 50 and len(filtered_result) < 5:
209
  # Likely got all contacts, filtered to very few - show warning
210
- formatted_output = f"**Warning:** API returned {original_count} total contacts. After filtering for '{original_url}', found {len(filtered_result)} matches.\n\n"
211
  formatted_output += "These results may not be accurate. The URL might not be in our database.\n\n"
212
  formatted_output += format_contact_results(filtered_result, url)
213
  else:
@@ -220,9 +220,9 @@ def search_contacts(url: str) -> tuple[str, str]:
220
  filtered_contacts = filter_contacts_by_url(actual_result['contacts'], url)
221
 
222
  if len(filtered_contacts) == 0:
223
- return f"No contacts found for: {original_url}\n\nThis URL may not be in our database.", json.dumps(result, indent=2)
224
  elif original_count > 50 and len(filtered_contacts) < 5:
225
- formatted_output = f"**Warning:** API returned {original_count} total contacts. After filtering for '{original_url}', found {len(filtered_contacts)} matches.\n\n"
226
  formatted_output += "These results may not be accurate. The URL might not be in our database.\n\n"
227
  formatted_output += format_contact_results({'contacts': filtered_contacts}, url)
228
  else:
@@ -250,17 +250,17 @@ def search_contacts(url: str) -> tuple[str, str]:
250
  return formatted_output, raw_json
251
 
252
  except json.JSONDecodeError:
253
- return f"Error: Invalid JSON response from API", response.text
254
 
255
  else:
256
- return f"API Error ({response.status_code}): {response.text}", ""
257
 
258
  except requests.exceptions.Timeout:
259
- return "Request timeout. Please try again.", ""
260
  except requests.exceptions.ConnectionError:
261
- return "Connection error. Please check your API endpoint.", ""
262
  except Exception as e:
263
- return f"Error: {str(e)}", ""
264
 
265
  def format_contact_results(results: Dict[Any, Any], url: str) -> str:
266
  """
@@ -340,6 +340,34 @@ def format_contact_results(results: Dict[Any, Any], url: str) -> str:
340
 
341
  return output
342
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
343
  # Create the Gradio interface
344
  with gr.Blocks(theme=theme, title="Kwekel Companies Contact Search Tool", css="""
345
  /* Root and body styles */
@@ -607,4 +635,4 @@ if __name__ == "__main__":
607
  server_port=7860,
608
  show_error=True,
609
  debug=True
610
- )
 
46
  # Button colors
47
  button_primary_background_fill="#1e40af",
48
  button_primary_background_fill_hover="#2563eb",
49
+ button_primary_text_color="#ffffff",
50
  button_secondary_background_fill="#404040",
51
  button_secondary_background_fill_hover="#555555",
52
+ button_secondary_text_color="#ffffff"
53
  )
54
 
55
  def normalize_url(url: str) -> str:
 
165
  """
166
 
167
  if not url.strip():
168
+ return "Please enter a website URL", ""
169
 
170
  # Clean and validate URL
171
  url = url.strip()
 
204
  # If we filtered out everything or got very few results compared to original,
205
  # it's likely the API returned all contacts instead of URL-specific ones
206
  if len(filtered_result) == 0:
207
+ return f"No contacts found for: {original_url}\n\nThis URL may not be in our database.", json.dumps(result, indent=2)
208
  elif original_count > 50 and len(filtered_result) < 5:
209
  # Likely got all contacts, filtered to very few - show warning
210
+ formatted_output = f"⚠️ **Warning:** API returned {original_count} total contacts. After filtering for '{original_url}', found {len(filtered_result)} matches.\n\n"
211
  formatted_output += "These results may not be accurate. The URL might not be in our database.\n\n"
212
  formatted_output += format_contact_results(filtered_result, url)
213
  else:
 
220
  filtered_contacts = filter_contacts_by_url(actual_result['contacts'], url)
221
 
222
  if len(filtered_contacts) == 0:
223
+ return f"No contacts found for: {original_url}\n\nThis URL may not be in our database.", json.dumps(result, indent=2)
224
  elif original_count > 50 and len(filtered_contacts) < 5:
225
+ formatted_output = f"⚠️ **Warning:** API returned {original_count} total contacts. After filtering for '{original_url}', found {len(filtered_contacts)} matches.\n\n"
226
  formatted_output += "These results may not be accurate. The URL might not be in our database.\n\n"
227
  formatted_output += format_contact_results({'contacts': filtered_contacts}, url)
228
  else:
 
250
  return formatted_output, raw_json
251
 
252
  except json.JSONDecodeError:
253
+ return f"Error: Invalid JSON response from API", response.text
254
 
255
  else:
256
+ return f"API Error ({response.status_code}): {response.text}", ""
257
 
258
  except requests.exceptions.Timeout:
259
+ return "Request timeout. Please try again.", ""
260
  except requests.exceptions.ConnectionError:
261
+ return "Connection error. Please check your API endpoint.", ""
262
  except Exception as e:
263
+ return f"Error: {str(e)}", ""
264
 
265
  def format_contact_results(results: Dict[Any, Any], url: str) -> str:
266
  """
 
340
 
341
  return output
342
 
343
+ def create_sample_data():
344
+ """Create sample data for demonstration"""
345
+ return '''# Contact Search Results for: example.com
346
+
347
+ **Found 2 contact(s):**
348
+
349
+ ## Contact 1
350
+ - **Name:** John Smith
351
+ - **Email:** john.smith@example.com
352
+ - **Title:** CEO
353
+ - **Company:** Example Corp
354
+ - **Phone:** (555) 123-4567
355
+ - **LinkedIn:** linkedin.com/in/johnsmith
356
+
357
+ ---
358
+
359
+ ## Contact 2
360
+ - **Name:** Jane Doe
361
+ - **Email:** jane.doe@example.com
362
+ - **Title:** VP of Sales
363
+ - **Company:** Example Corp
364
+ - **Phone:** (555) 123-4568
365
+ - **LinkedIn:** linkedin.com/in/janedoe
366
+
367
+ ---
368
+
369
+ *Search completed at: 2025-01-15 10:30:00*'''
370
+
371
  # Create the Gradio interface
372
  with gr.Blocks(theme=theme, title="Kwekel Companies Contact Search Tool", css="""
373
  /* Root and body styles */
 
635
  server_port=7860,
636
  show_error=True,
637
  debug=True
638
+ )