JayBene1 commited on
Commit
2840e36
·
verified ·
1 Parent(s): 96dd8ea

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -59
app.py CHANGED
@@ -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
  """
@@ -395,13 +395,13 @@ with gr.Blocks(theme=theme, title="Kwekel Companies Contact Search Tool", css=""
395
 
396
  /* Header styles */
397
  .header {
398
- background: linear-gradient(135deg, #1e40af 0%, #2563eb 100%) !important;
399
  color: white;
400
  padding: 2rem;
401
  border-radius: 0.5rem;
402
  margin-bottom: 2rem;
403
  text-align: center;
404
- border: 1px solid #1e40af;
405
  }
406
  .header h1 {
407
  margin: 0;
@@ -443,28 +443,6 @@ with gr.Blocks(theme=theme, title="Kwekel Companies Contact Search Tool", css=""
443
  color: #e5e5e5 !important;
444
  }
445
 
446
- /* Blue background for specific blocks */
447
- .blue-header-block {
448
- background: linear-gradient(135deg, #1e40af 0%, #2563eb 100%) !important;
449
- border: 1px solid #1e40af !important;
450
- border-radius: 0.5rem !important;
451
- padding: 1rem !important;
452
- }
453
-
454
- .blue-header-block .gr-label {
455
- color: #ffffff !important;
456
- font-weight: 600 !important;
457
- }
458
-
459
- .blue-header-block .gr-textbox,
460
- .blue-header-block .gr-markdown,
461
- .blue-header-block .gr-code {
462
- background-color: #2d2d2d !important;
463
- border: 1px solid #404040 !important;
464
- border-radius: 0.375rem !important;
465
- margin-top: 0.5rem !important;
466
- }
467
-
468
  /* Input field styles */
469
  .gr-textbox input,
470
  .gr-textbox textarea,
@@ -549,9 +527,9 @@ with gr.Blocks(theme=theme, title="Kwekel Companies Contact Search Tool", css=""
549
  }
550
  """) as demo:
551
 
552
- # Header with blue background
553
  gr.HTML("""
554
- <div class="header blue-header-block">
555
  <h1>Kwekel Companies Contact Search Tool</h1>
556
  </div>
557
  """)
@@ -572,14 +550,12 @@ with gr.Blocks(theme=theme, title="Kwekel Companies Contact Search Tool", css=""
572
 
573
  with gr.Row():
574
  with gr.Column(scale=2):
575
- # Website URL input with blue header
576
- with gr.Group(elem_classes="blue-header-block"):
577
- url_input = gr.Textbox(
578
- label="Website URL",
579
- placeholder="example.com or https://example.com",
580
- info="Enter the website URL to search for contacts",
581
- lines=1
582
- )
583
 
584
  with gr.Row():
585
  search_btn = gr.Button("Search Contacts", variant="primary", scale=2)
@@ -593,13 +569,11 @@ with gr.Blocks(theme=theme, title="Kwekel Companies Contact Search Tool", css=""
593
  )
594
 
595
  with gr.Column(scale=1):
596
- # Raw JSON Response with blue header
597
- with gr.Group(elem_classes="blue-header-block"):
598
- json_output = gr.Code(
599
- label="Raw JSON Response",
600
- language="json",
601
- value=""
602
- )
603
 
604
  # Event handlers
605
  search_btn.click(
@@ -608,13 +582,6 @@ with gr.Blocks(theme=theme, title="Kwekel Companies Contact Search Tool", css=""
608
  outputs=[results_output, json_output]
609
  )
610
 
611
- # Add Enter key functionality to URL input
612
- url_input.submit(
613
- fn=search_contacts,
614
- inputs=[url_input],
615
- outputs=[results_output, json_output]
616
- )
617
-
618
  clear_btn.click(
619
  fn=lambda: ("", ""),
620
  outputs=[url_input, results_output]
@@ -635,4 +602,4 @@ if __name__ == "__main__":
635
  server_port=7860,
636
  show_error=True,
637
  debug=True
638
- )
 
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
  """
 
395
 
396
  /* Header styles */
397
  .header {
398
+ background: linear-gradient(135deg, #1a1a1a 0%, #2d2d2d 100%);
399
  color: white;
400
  padding: 2rem;
401
  border-radius: 0.5rem;
402
  margin-bottom: 2rem;
403
  text-align: center;
404
+ border: 1px solid #404040;
405
  }
406
  .header h1 {
407
  margin: 0;
 
443
  color: #e5e5e5 !important;
444
  }
445
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
446
  /* Input field styles */
447
  .gr-textbox input,
448
  .gr-textbox textarea,
 
527
  }
528
  """) as demo:
529
 
530
+ # Header
531
  gr.HTML("""
532
+ <div class="header">
533
  <h1>Kwekel Companies Contact Search Tool</h1>
534
  </div>
535
  """)
 
550
 
551
  with gr.Row():
552
  with gr.Column(scale=2):
553
+ url_input = gr.Textbox(
554
+ label="Website URL",
555
+ placeholder="example.com or https://example.com",
556
+ info="Enter the website URL to search for contacts",
557
+ lines=1
558
+ )
 
 
559
 
560
  with gr.Row():
561
  search_btn = gr.Button("Search Contacts", variant="primary", scale=2)
 
569
  )
570
 
571
  with gr.Column(scale=1):
572
+ json_output = gr.Code(
573
+ label="Raw JSON Response",
574
+ language="json",
575
+ value=""
576
+ )
 
 
577
 
578
  # Event handlers
579
  search_btn.click(
 
582
  outputs=[results_output, json_output]
583
  )
584
 
 
 
 
 
 
 
 
585
  clear_btn.click(
586
  fn=lambda: ("", ""),
587
  outputs=[url_input, results_output]
 
602
  server_port=7860,
603
  show_error=True,
604
  debug=True
605
+ )