JayBene1 commited on
Commit
68ee454
·
verified ·
1 Parent(s): 72da531

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +57 -76
app.py CHANGED
@@ -36,8 +36,8 @@ theme = gr.themes.Soft(
36
  block_title_text_color_dark="#e5e5e5",
37
 
38
  # Input colors (using valid property names)
39
- input_background_fill="#3b3a3a",
40
- input_background_fill_dark="#3b3a3a",
41
  input_border_color="#555555",
42
  input_border_color_dark="#555555",
43
  input_placeholder_color="#a0a0a0",
@@ -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,34 +340,6 @@ def format_contact_results(results: Dict[Any, Any], url: str) -> str:
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 */
@@ -393,15 +365,16 @@ with gr.Blocks(theme=theme, title="Kwekel Companies Contact Search Tool", css=""
393
  color: #e5e5e5 !important;
394
  }
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;
@@ -468,16 +441,26 @@ with gr.Blocks(theme=theme, title="Kwekel Companies Contact Search Tool", css=""
468
  color: #e5e5e5 !important;
469
  }
470
 
 
 
 
 
 
471
  /* Markdown and code styles */
472
  .gr-markdown, .gr-markdown * {
473
  color: #e5e5e5 !important;
474
  }
475
 
476
  .gr-code, .gr-code * {
477
- color: #e5e5e5 !important;
478
  background-color: #2d2d2d !important;
479
  }
480
 
 
 
 
 
 
481
  /* Form and block styles */
482
  .gr-form, .gr-form * {
483
  color: #e5e5e5 !important;
@@ -497,43 +480,23 @@ with gr.Blocks(theme=theme, title="Kwekel Companies Contact Search Tool", css=""
497
  background-color: #1a1a1a !important;
498
  }
499
 
500
- /* Specific block background colors for Website URL and Raw JSON Response */
501
- .gr-textbox, .gr-code {
502
- background-color: #3b3a3a !important;
503
- }
504
-
505
- .gr-textbox .gr-box, .gr-code .gr-box {
506
- background-color: #3b3a3a !important;
507
- }
508
-
509
- /* More specific targeting for textbox and code blocks */
510
- .gr-textbox > div, .gr-code > div {
511
- background-color: #3b3a3a !important;
512
- }
513
-
514
- /* Target the actual input container */
515
- .gr-textbox .gr-input, .gr-code .gr-input {
516
- background-color: #3b3a3a !important;
517
- }
518
-
519
- /* Target Gradio component containers */
520
- div[data-testid="textbox"], div[data-testid="code"] {
521
- background-color: #3b3a3a !important;
522
  }
523
 
524
- /* Additional targeting for component wrappers */
525
- .gr-form > div, .gr-column > div {
526
- background-color: #3b3a3a !important;
 
 
 
527
  }
528
 
529
- /* Override any block backgrounds specifically */
530
- .gradio-textbox, .gradio-code {
531
- background-color: #3b3a3a !important;
532
- }
533
-
534
- /* Button text visibility */
535
- .gr-button {
536
- color: #ffffff !important;
537
  }
538
 
539
  /* Ensure info text is visible */
@@ -548,6 +511,11 @@ with gr.Blocks(theme=theme, title="Kwekel Companies Contact Search Tool", css=""
548
  color: #e5e5e5 !important;
549
  }
550
 
 
 
 
 
 
551
  /* Override any remaining dark text */
552
  p, span, div, h1, h2, h3, h4, h5, h6, li, td, th {
553
  color: #e5e5e5 !important;
@@ -559,6 +527,19 @@ with gr.Blocks(theme=theme, title="Kwekel Companies Contact Search Tool", css=""
559
  background-color: #2d2d2d !important;
560
  border-color: #1e40af !important;
561
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
562
  """) as demo:
563
 
564
  # Header
 
36
  block_title_text_color_dark="#e5e5e5",
37
 
38
  # Input colors (using valid property names)
39
+ input_background_fill="#2d2d2d",
40
+ input_background_fill_dark="#2d2d2d",
41
  input_border_color="#555555",
42
  input_border_color_dark="#555555",
43
  input_placeholder_color="#a0a0a0",
 
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
  # Create the Gradio interface
344
  with gr.Blocks(theme=theme, title="Kwekel Companies Contact Search Tool", css="""
345
  /* Root and body styles */
 
365
  color: #e5e5e5 !important;
366
  }
367
 
368
+ /* Header styles with blue gradient */
369
  .header {
370
+ background: linear-gradient(135deg, #1e3a8a 0%, #3b82f6 50%, #1e40af 100%);
371
  color: white;
372
  padding: 2rem;
373
  border-radius: 0.5rem;
374
  margin-bottom: 2rem;
375
  text-align: center;
376
  border: 1px solid #404040;
377
+ box-shadow: 0 4px 15px rgba(30, 58, 138, 0.3);
378
  }
379
  .header h1 {
380
  margin: 0;
 
441
  color: #e5e5e5 !important;
442
  }
443
 
444
+ /* Specific styling for Website URL input label */
445
+ .gr-textbox:has(input[placeholder*="example.com"]) label {
446
+ color: #3b3a3a !important;
447
+ }
448
+
449
  /* Markdown and code styles */
450
  .gr-markdown, .gr-markdown * {
451
  color: #e5e5e5 !important;
452
  }
453
 
454
  .gr-code, .gr-code * {
455
+ color: #3b3a3a !important;
456
  background-color: #2d2d2d !important;
457
  }
458
 
459
+ /* Code block specific styling */
460
+ .gr-code pre, .gr-code pre * {
461
+ color: #3b3a3a !important;
462
+ }
463
+
464
  /* Form and block styles */
465
  .gr-form, .gr-form * {
466
  color: #e5e5e5 !important;
 
480
  background-color: #1a1a1a !important;
481
  }
482
 
483
+ /* Button text visibility */
484
+ .gr-button {
485
+ color: #ffffff !important;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
486
  }
487
 
488
+ /* Primary button with blue gradient */
489
+ .gr-button.primary {
490
+ background: linear-gradient(135deg, #1e3a8a 0%, #3b82f6 50%, #1e40af 100%) !important;
491
+ border: none !important;
492
+ box-shadow: 0 4px 15px rgba(30, 58, 138, 0.3) !important;
493
+ transition: all 0.3s ease !important;
494
  }
495
 
496
+ .gr-button.primary:hover {
497
+ background: linear-gradient(135deg, #1e40af 0%, #3b82f6 50%, #2563eb 100%) !important;
498
+ box-shadow: 0 6px 20px rgba(30, 58, 138, 0.4) !important;
499
+ transform: translateY(-2px) !important;
 
 
 
 
500
  }
501
 
502
  /* Ensure info text is visible */
 
511
  color: #e5e5e5 !important;
512
  }
513
 
514
+ /* Override for Website URL label specifically */
515
+ .gr-textbox:has(input[placeholder*="example.com"]) .gr-textbox-label {
516
+ color: #3b3a3a !important;
517
+ }
518
+
519
  /* Override any remaining dark text */
520
  p, span, div, h1, h2, h3, h4, h5, h6, li, td, th {
521
  color: #e5e5e5 !important;
 
527
  background-color: #2d2d2d !important;
528
  border-color: #1e40af !important;
529
  }
530
+
531
+ /* Specific targeting for the Website URL input text */
532
+ .gr-textbox input[placeholder*="example.com"] {
533
+ color: #3b3a3a !important;
534
+ }
535
+
536
+ /* JSON code block text color */
537
+ .gr-code[data-testid*="json"] pre,
538
+ .gr-code[data-testid*="json"] code,
539
+ .gr-code[language="json"] pre,
540
+ .gr-code[language="json"] code {
541
+ color: #3b3a3a !important;
542
+ }
543
  """) as demo:
544
 
545
  # Header