JayBene1 commited on
Commit
70442a2
Β·
verified Β·
1 Parent(s): e4ac4c8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -21
app.py CHANGED
@@ -4,6 +4,9 @@ import json
4
  from typing import List, Dict, Any
5
  import pandas as pd
6
 
 
 
 
7
  # Professional color scheme inspired by corporate/real estate companies
8
  theme = gr.themes.Soft(
9
  primary_hue="blue",
@@ -31,13 +34,12 @@ theme = gr.themes.Soft(
31
  button_secondary_text_color="#334155"
32
  )
33
 
34
- def search_contacts(url: str, api_endpoint: str = None) -> tuple[str, str]:
35
  """
36
  Search for contacts associated with a given URL using the Hugging Face API.
37
 
38
  Args:
39
  url: The website URL to search for contacts
40
- api_endpoint: Your Hugging Face API endpoint URL
41
 
42
  Returns:
43
  Tuple of (formatted_results, raw_json)
@@ -46,9 +48,6 @@ def search_contacts(url: str, api_endpoint: str = None) -> tuple[str, str]:
46
  if not url.strip():
47
  return "❌ Please enter a website URL", ""
48
 
49
- if not api_endpoint or not api_endpoint.strip():
50
- return "❌ Please provide your Hugging Face API endpoint URL", ""
51
-
52
  # Clean and validate URL
53
  url = url.strip()
54
  if not url.startswith(('http://', 'https://')):
@@ -57,8 +56,7 @@ def search_contacts(url: str, api_endpoint: str = None) -> tuple[str, str]:
57
  try:
58
  # Prepare the API request
59
  headers = {
60
- 'Content-Type': 'application/json',
61
- 'Authorization': f'Bearer {api_endpoint.split("/")[-1]}' # Adjust based on your API auth
62
  }
63
 
64
  payload = {
@@ -69,9 +67,9 @@ def search_contacts(url: str, api_endpoint: str = None) -> tuple[str, str]:
69
  }
70
  }
71
 
72
- # Make the API request
73
  response = requests.post(
74
- api_endpoint,
75
  headers=headers,
76
  json=payload,
77
  timeout=30
@@ -256,27 +254,20 @@ with gr.Blocks(theme=theme, title="Contact Search - Kwekel Companies", css="""
256
  """)
257
 
258
  # Info box
259
- gr.HTML("""
260
  <div class="info-box">
261
  <h3>πŸ“‹ Instructions:</h3>
262
  <ol>
263
- <li>Enter your Hugging Face API endpoint URL in the first field</li>
264
  <li>Enter the website URL you want to search for contacts</li>
265
  <li>Click "Search Contacts" to get results</li>
266
  <li>View formatted results and raw JSON response</li>
267
  </ol>
 
268
  </div>
269
  """)
270
 
271
  with gr.Row():
272
  with gr.Column(scale=2):
273
- api_endpoint = gr.Textbox(
274
- label="πŸ”— Hugging Face API Endpoint",
275
- placeholder="https://your-model-endpoint.hf.space/api/v1/predict",
276
- info="Enter your Hugging Face API endpoint URL",
277
- lines=1
278
- )
279
-
280
  url_input = gr.Textbox(
281
  label="🌐 Website URL",
282
  placeholder="example.com or https://example.com",
@@ -308,7 +299,7 @@ with gr.Blocks(theme=theme, title="Contact Search - Kwekel Companies", css="""
308
  # Event handlers
309
  search_btn.click(
310
  fn=search_contacts,
311
- inputs=[url_input, api_endpoint],
312
  outputs=[results_output, json_output]
313
  )
314
 
@@ -318,8 +309,8 @@ with gr.Blocks(theme=theme, title="Contact Search - Kwekel Companies", css="""
318
  )
319
 
320
  clear_btn.click(
321
- fn=lambda: ("", "", ""),
322
- outputs=[url_input, results_output, json_output]
323
  )
324
 
325
  # Footer
 
4
  from typing import List, Dict, Any
5
  import pandas as pd
6
 
7
+ # Hardcoded API endpoint
8
+ API_ENDPOINT = "https://huggingface.co/spaces/JayBene1/testapicontacts"
9
+
10
  # Professional color scheme inspired by corporate/real estate companies
11
  theme = gr.themes.Soft(
12
  primary_hue="blue",
 
34
  button_secondary_text_color="#334155"
35
  )
36
 
37
+ def search_contacts(url: str) -> tuple[str, str]:
38
  """
39
  Search for contacts associated with a given URL using the Hugging Face API.
40
 
41
  Args:
42
  url: The website URL to search for contacts
 
43
 
44
  Returns:
45
  Tuple of (formatted_results, raw_json)
 
48
  if not url.strip():
49
  return "❌ Please enter a website URL", ""
50
 
 
 
 
51
  # Clean and validate URL
52
  url = url.strip()
53
  if not url.startswith(('http://', 'https://')):
 
56
  try:
57
  # Prepare the API request
58
  headers = {
59
+ 'Content-Type': 'application/json'
 
60
  }
61
 
62
  payload = {
 
67
  }
68
  }
69
 
70
+ # Make the API request to the hardcoded endpoint
71
  response = requests.post(
72
+ API_ENDPOINT,
73
  headers=headers,
74
  json=payload,
75
  timeout=30
 
254
  """)
255
 
256
  # Info box
257
+ gr.HTML(f"""
258
  <div class="info-box">
259
  <h3>πŸ“‹ Instructions:</h3>
260
  <ol>
 
261
  <li>Enter the website URL you want to search for contacts</li>
262
  <li>Click "Search Contacts" to get results</li>
263
  <li>View formatted results and raw JSON response</li>
264
  </ol>
265
+ <p><strong>API Endpoint:</strong> {API_ENDPOINT}</p>
266
  </div>
267
  """)
268
 
269
  with gr.Row():
270
  with gr.Column(scale=2):
 
 
 
 
 
 
 
271
  url_input = gr.Textbox(
272
  label="🌐 Website URL",
273
  placeholder="example.com or https://example.com",
 
299
  # Event handlers
300
  search_btn.click(
301
  fn=search_contacts,
302
+ inputs=[url_input],
303
  outputs=[results_output, json_output]
304
  )
305
 
 
309
  )
310
 
311
  clear_btn.click(
312
+ fn=lambda: ("", ""),
313
+ outputs=[url_input, results_output]
314
  )
315
 
316
  # Footer