JayBene1 commited on
Commit
9fe5059
Β·
verified Β·
1 Parent(s): e708c6a

Create app.y

Browse files
Files changed (1) hide show
  1. app.y +423 -0
app.y ADDED
@@ -0,0 +1,423 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import requests
3
+ import re
4
+ import json
5
+ from urllib.parse import urlparse, urljoin
6
+ import time
7
+ import random
8
+
9
+ # Mock contacts database (same as your API)
10
+ CONTACTS_DB = [
11
+ {
12
+ "id": 1,
13
+ "first_name": "Sarah",
14
+ "last_name": "Chen",
15
+ "email": "sarah.chen@techflowsolutions.com",
16
+ "phone": "+1-555-0101",
17
+ "job_title": "CTO",
18
+ "company": "TechFlow Solutions",
19
+ "website": "https://techflowsolutions.com"
20
+ },
21
+ {
22
+ "id": 2,
23
+ "first_name": "Marcus",
24
+ "last_name": "Rodriguez",
25
+ "email": "m.rodriguez@techflowsolutions.com",
26
+ "phone": "+1-555-0102",
27
+ "job_title": "Senior Developer",
28
+ "company": "TechFlow Solutions",
29
+ "website": "https://techflowsolutions.com"
30
+ },
31
+ {
32
+ "id": 3,
33
+ "first_name": "Emma",
34
+ "last_name": "Thompson",
35
+ "email": "emma@greenleafconsult.com",
36
+ "phone": "+1-555-0201",
37
+ "job_title": "Managing Partner",
38
+ "company": "GreenLeaf Consulting",
39
+ "website": "https://greenleafconsult.com"
40
+ },
41
+ {
42
+ "id": 4,
43
+ "first_name": "David",
44
+ "last_name": "Park",
45
+ "email": "david.park@greenleafconsult.com",
46
+ "phone": "+1-555-0202",
47
+ "job_title": "Environmental Analyst",
48
+ "company": "GreenLeaf Consulting",
49
+ "website": "https://greenleafconsult.com"
50
+ },
51
+ {
52
+ "id": 5,
53
+ "first_name": "Jessica",
54
+ "last_name": "Williams",
55
+ "email": "jessica@blueskymarketing.net",
56
+ "phone": "+1-555-0301",
57
+ "job_title": "Creative Director",
58
+ "company": "BlueSky Marketing",
59
+ "website": "https://blueskymarketing.net"
60
+ },
61
+ {
62
+ "id": 6,
63
+ "first_name": "Ryan",
64
+ "last_name": "Mitchell",
65
+ "email": "ryan.mitchell@blueskymarketing.net",
66
+ "phone": "+1-555-0302",
67
+ "job_title": "Account Manager",
68
+ "company": "BlueSky Marketing",
69
+ "website": "https://blueskymarketing.net"
70
+ },
71
+ {
72
+ "id": 7,
73
+ "first_name": "Lisa",
74
+ "last_name": "Zhang",
75
+ "email": "l.zhang@quantumdynamics.org",
76
+ "phone": "+1-555-0401",
77
+ "job_title": "Research Director",
78
+ "company": "Quantum Dynamics Corp",
79
+ "website": "https://quantumdynamics.org"
80
+ },
81
+ {
82
+ "id": 8,
83
+ "first_name": "Ahmed",
84
+ "last_name": "Hassan",
85
+ "email": "ahmed.hassan@quantumdynamics.org",
86
+ "phone": "+1-555-0402",
87
+ "job_title": "Quantum Engineer",
88
+ "company": "Quantum Dynamics Corp",
89
+ "website": "https://quantumdynamics.org"
90
+ },
91
+ {
92
+ "id": 9,
93
+ "first_name": "Maria",
94
+ "last_name": "Gonzalez",
95
+ "email": "maria@stellarlogistics.biz",
96
+ "phone": "+1-555-0501",
97
+ "job_title": "Operations Manager",
98
+ "company": "Stellar Logistics",
99
+ "website": "https://stellarlogistics.biz"
100
+ },
101
+ {
102
+ "id": 10,
103
+ "first_name": "James",
104
+ "last_name": "O'Connor",
105
+ "email": "james.oconnor@stellarlogistics.biz",
106
+ "phone": "+1-555-0502",
107
+ "job_title": "Fleet Coordinator",
108
+ "company": "Stellar Logistics",
109
+ "website": "https://stellarlogistics.biz"
110
+ },
111
+ {
112
+ "id": 11,
113
+ "first_name": "Robert",
114
+ "last_name": "Kim",
115
+ "email": "robert.kim@nexusfinancial.pro",
116
+ "phone": "+1-555-0601",
117
+ "job_title": "Senior Advisor",
118
+ "company": "Nexus Financial",
119
+ "website": "https://nexusfinancial.pro"
120
+ },
121
+ {
122
+ "id": 12,
123
+ "first_name": "Catherine",
124
+ "last_name": "Lee",
125
+ "email": "catherine@nexusfinancial.pro",
126
+ "phone": "+1-555-0602",
127
+ "job_title": "Investment Analyst",
128
+ "company": "Nexus Financial",
129
+ "website": "https://nexusfinancial.pro"
130
+ },
131
+ {
132
+ "id": 13,
133
+ "first_name": "Michael",
134
+ "last_name": "Johnson",
135
+ "email": "m.johnson@horizonhealth.care",
136
+ "phone": "+1-555-0701",
137
+ "job_title": "Chief Medical Officer",
138
+ "company": "Horizon Health Systems",
139
+ "website": "https://horizonhealth.care"
140
+ },
141
+ {
142
+ "id": 14,
143
+ "first_name": "Jennifer",
144
+ "last_name": "Adams",
145
+ "email": "jennifer.adams@horizonhealth.care",
146
+ "phone": "+1-555-0702",
147
+ "job_title": "Head Nurse",
148
+ "company": "Horizon Health Systems",
149
+ "website": "https://horizonhealth.care"
150
+ },
151
+ {
152
+ "id": 15,
153
+ "first_name": "Tony",
154
+ "last_name": "Ricci",
155
+ "email": "tony.ricci@phoenixmfg.com",
156
+ "phone": "+1-555-0801",
157
+ "job_title": "Plant Manager",
158
+ "company": "Phoenix Manufacturing",
159
+ "website": "https://phoenixmfg.com"
160
+ },
161
+ {
162
+ "id": 16,
163
+ "first_name": "Linda",
164
+ "last_name": "Martinez",
165
+ "email": "linda.martinez@phoenixmfg.com",
166
+ "phone": "+1-555-0802",
167
+ "job_title": "Quality Control Supervisor",
168
+ "company": "Phoenix Manufacturing",
169
+ "website": "https://phoenixmfg.com"
170
+ },
171
+ {
172
+ "id": 17,
173
+ "first_name": "Patricia",
174
+ "last_name": "White",
175
+ "email": "patricia.white@alpineeducation.edu",
176
+ "phone": "+1-555-0901",
177
+ "job_title": "Director of Programs",
178
+ "company": "Alpine Education Group",
179
+ "website": "https://alpineeducation.edu"
180
+ },
181
+ {
182
+ "id": 18,
183
+ "first_name": "Kevin",
184
+ "last_name": "Brown",
185
+ "email": "kevin.brown@alpineeducation.edu",
186
+ "phone": "+1-555-0902",
187
+ "job_title": "Curriculum Specialist",
188
+ "company": "Alpine Education Group",
189
+ "website": "https://alpineeducation.edu"
190
+ },
191
+ {
192
+ "id": 19,
193
+ "first_name": "Sophia",
194
+ "last_name": "Taylor",
195
+ "email": "sophia@crimsoncreative.studio",
196
+ "phone": "+1-555-1001",
197
+ "job_title": "Art Director",
198
+ "company": "Crimson Creative Studio",
199
+ "website": "https://crimsoncreative.studio"
200
+ },
201
+ {
202
+ "id": 20,
203
+ "first_name": "Alex",
204
+ "last_name": "Cooper",
205
+ "email": "alex.cooper@crimsoncreative.studio",
206
+ "phone": "+1-555-1002",
207
+ "job_title": "Graphic Designer",
208
+ "company": "Crimson Creative Studio",
209
+ "website": "https://crimsoncreative.studio"
210
+ }
211
+ ]
212
+
213
+ def extract_domain(url):
214
+ """Extract domain from URL"""
215
+ try:
216
+ parsed = urlparse(url)
217
+ domain = parsed.netloc.lower()
218
+ # Remove www. if present
219
+ if domain.startswith('www.'):
220
+ domain = domain[4:]
221
+ return domain
222
+ except:
223
+ return ""
224
+
225
+ def find_contacts_by_website(website_url):
226
+ """Find contacts that match the website domain"""
227
+ target_domain = extract_domain(website_url)
228
+ if not target_domain:
229
+ return []
230
+
231
+ print(f"Searching for domain: {target_domain}") # Debug info
232
+
233
+ matching_contacts = []
234
+ for contact in CONTACTS_DB:
235
+ contact_domain = extract_domain(contact['website'])
236
+ print(f"Comparing with: {contact_domain}") # Debug info
237
+
238
+ # Exact domain match or subdomain match
239
+ if target_domain == contact_domain or target_domain in contact_domain or contact_domain in target_domain:
240
+ matching_contacts.append(contact)
241
+
242
+ print(f"Found {len(matching_contacts)} matching contacts") # Debug info
243
+ return matching_contacts
244
+
245
+ def simulate_website_scraping(url):
246
+ """Simulate scraping a website and finding contact information"""
247
+ # Add some delay to simulate real scraping
248
+ time.sleep(random.uniform(1, 2))
249
+
250
+ # Find matching contacts from our database
251
+ contacts = find_contacts_by_website(url)
252
+
253
+ # Only return contacts if we found exact matches
254
+ # Don't return random contacts if no match found
255
+ return contacts
256
+
257
+ def search_website_contacts(website_url, max_results=10):
258
+ """Main function to search for contacts on a website"""
259
+ if not website_url:
260
+ return "Please enter a website URL", ""
261
+
262
+ # Clean up URL
263
+ if not website_url.startswith(('http://', 'https://')):
264
+ website_url = 'https://' + website_url
265
+
266
+ try:
267
+ # Simulate finding contacts
268
+ contacts = simulate_website_scraping(website_url)
269
+
270
+ if not contacts:
271
+ return f"No contacts found on {website_url}. \n\nThis website is not in our contact database. Try one of the sample websites listed below, or the website might not have publicly available contact information.", ""
272
+
273
+ # Limit results
274
+ contacts = contacts[:max_results]
275
+
276
+ # Format results
277
+ results_text = f"Found {len(contacts)} contacts on {website_url}:\n\n"
278
+
279
+ contact_data = []
280
+ for i, contact in enumerate(contacts, 1):
281
+ results_text += f"**Contact {i}:**\n"
282
+ results_text += f"β€’ First Name: {contact['first_name']}\n"
283
+ results_text += f"β€’ Last Name: {contact['last_name']}\n"
284
+ results_text += f"β€’ Job Title: {contact['job_title']}\n"
285
+ results_text += f"β€’ Email: {contact['email']}\n"
286
+ results_text += f"β€’ Phone: {contact['phone']}\n"
287
+ results_text += f"β€’ Company: {contact['company']}\n\n"
288
+
289
+ # Prepare data for CSV/table format
290
+ contact_data.append([
291
+ contact['first_name'],
292
+ contact['last_name'],
293
+ contact['job_title'],
294
+ contact['email'],
295
+ contact['phone'],
296
+ contact['company']
297
+ ])
298
+
299
+ # Create a simple table format for the second output
300
+ table_text = "First Name,Last Name,Job Title,Email,Phone,Company\n"
301
+ for contact in contacts:
302
+ table_text += f"{contact['first_name']},{contact['last_name']},{contact['job_title']},{contact['email']},{contact['phone']},{contact['company']}\n"
303
+
304
+ return results_text, table_text
305
+
306
+ except Exception as e:
307
+ return f"Error searching website: {str(e)}", ""
308
+
309
+ def get_all_available_websites():
310
+ """Get list of all available websites from the database"""
311
+ websites = list(set([contact['website'] for contact in CONTACTS_DB]))
312
+ return "\n".join(sorted(websites))
313
+
314
+ # Create Gradio interface
315
+ with gr.Blocks(title="Website Contact Finder", theme=gr.themes.Soft()) as app:
316
+ gr.HTML("""
317
+ <div style="text-align: center; padding: 20px;">
318
+ <h1>πŸ” Website Contact Finder</h1>
319
+ <p>Search any website to find contact information including names, job titles, phone numbers, and emails</p>
320
+ </div>
321
+ """)
322
+
323
+ with gr.Row():
324
+ with gr.Column(scale=2):
325
+ website_input = gr.Textbox(
326
+ label="Website URL",
327
+ placeholder="Enter website URL (e.g., techflowsolutions.com or https://greenleafconsult.com)",
328
+ value=""
329
+ )
330
+
331
+ max_results = gr.Slider(
332
+ minimum=1,
333
+ maximum=20,
334
+ value=5,
335
+ step=1,
336
+ label="Maximum Results"
337
+ )
338
+
339
+ search_btn = gr.Button("πŸ” Search Contacts", variant="primary", size="lg")
340
+
341
+ with gr.Column(scale=1):
342
+ gr.HTML("""
343
+ <div style="background: #f0f0f0; padding: 15px; border-radius: 10px;">
344
+ <h3>πŸ’‘ Tips:</h3>
345
+ <ul>
346
+ <li>Enter any website URL</li>
347
+ <li>Works with or without https://</li>
348
+ <li>Try our sample websites below</li>
349
+ <li>Results include full contact details</li>
350
+ </ul>
351
+ </div>
352
+ """)
353
+
354
+ with gr.Row():
355
+ results_display = gr.Textbox(
356
+ label="Contact Results",
357
+ lines=15,
358
+ max_lines=30,
359
+ show_copy_button=True
360
+ )
361
+
362
+ csv_output = gr.Textbox(
363
+ label="CSV Format (Copy & Paste into Excel)",
364
+ lines=15,
365
+ max_lines=30,
366
+ show_copy_button=True
367
+ )
368
+
369
+ # Sample websites section
370
+ with gr.Accordion("πŸ“‹ Available Sample Websites", open=False):
371
+ sample_websites = gr.Textbox(
372
+ label="Sample Websites from Database",
373
+ value=get_all_available_websites(),
374
+ lines=10,
375
+ interactive=False
376
+ )
377
+
378
+ # Quick search buttons for sample websites
379
+ with gr.Row():
380
+ gr.HTML("<h3>πŸš€ Quick Search Sample Websites:</h3>")
381
+
382
+ with gr.Row():
383
+ quick_btn1 = gr.Button("TechFlow Solutions", size="sm")
384
+ quick_btn2 = gr.Button("GreenLeaf Consulting", size="sm")
385
+ quick_btn3 = gr.Button("BlueSky Marketing", size="sm")
386
+ quick_btn4 = gr.Button("Quantum Dynamics", size="sm")
387
+
388
+ with gr.Row():
389
+ quick_btn5 = gr.Button("Stellar Logistics", size="sm")
390
+ quick_btn6 = gr.Button("Nexus Financial", size="sm")
391
+ quick_btn7 = gr.Button("Horizon Health", size="sm")
392
+ quick_btn8 = gr.Button("Phoenix Manufacturing", size="sm")
393
+
394
+ # Event handlers
395
+ search_btn.click(
396
+ fn=search_website_contacts,
397
+ inputs=[website_input, max_results],
398
+ outputs=[results_display, csv_output]
399
+ )
400
+
401
+ # Quick search button handlers
402
+ quick_btn1.click(lambda: "techflowsolutions.com", outputs=website_input)
403
+ quick_btn2.click(lambda: "greenleafconsult.com", outputs=website_input)
404
+ quick_btn3.click(lambda: "blueskymarketing.net", outputs=website_input)
405
+ quick_btn4.click(lambda: "quantumdynamics.org", outputs=website_input)
406
+ quick_btn5.click(lambda: "stellarlogistics.biz", outputs=website_input)
407
+ quick_btn6.click(lambda: "nexusfinancial.pro", outputs=website_input)
408
+ quick_btn7.click(lambda: "horizonhealth.care", outputs=website_input)
409
+ quick_btn8.click(lambda: "phoenixmfg.com", outputs=website_input)
410
+
411
+ # Examples
412
+ gr.Examples(
413
+ examples=[
414
+ ["techflowsolutions.com", 5],
415
+ ["https://greenleafconsult.com", 3],
416
+ ["blueskymarketing.net", 2],
417
+ ["quantumdynamics.org", 4]
418
+ ],
419
+ inputs=[website_input, max_results]
420
+ )
421
+
422
+ if __name__ == "__main__":
423
+ app.launch()