Spaces:
Build error
Build error
| import gradio as gr | |
| from lead_management import fetch_duckduckgo_search_results, extract_company_info, insert_data, read_leads, remove_duplicates | |
| EXCEL_FILE = "leads.xlsx" | |
| # Logic | |
| def run_search(query, num_results): | |
| html_content = fetch_duckduckgo_search_results(query, num_results) | |
| data = extract_company_info(html_content) | |
| insert_data(EXCEL_FILE, data) | |
| return "Search and insertion completed." | |
| def view_leads(): | |
| leads = read_leads(EXCEL_FILE) | |
| leads_display = [] | |
| for lead in leads: | |
| lead = list(lead) | |
| lead[4] = f'<a href="{lead[4]}" target="_blank">{lead[4]}</a>' if lead[4] else '' | |
| lead[5] = f'<a href="{lead[5]}" target="_blank">{lead[5]}</a>' if lead[5] else '' | |
| leads_display.append(lead) | |
| return format_table(leads_display) | |
| def format_table(leads): | |
| table = '<table border="1">' | |
| headers = ["Name", "Email", "Mobile Number", "POC", "Website", "LinkedIn Profile", "Status", "Search Date"] | |
| table += '<tr>' + ''.join([f'<th>{header}</th>' for header in headers]) + '</tr>' | |
| for lead in leads: | |
| table += '<tr>' + ''.join([f'<td>{field}</td>' for field in lead]) + '</tr>' | |
| table += '</table>' | |
| return table | |
| def download_leads(): | |
| return EXCEL_FILE | |
| def remove_and_return_html(): | |
| remove_duplicates(EXCEL_FILE) | |
| return view_leads() | |
| def run_combined_query(preset, custom, num): | |
| query = custom.strip() if custom else preset | |
| return run_search(query, num) | |
| # UI | |
| with gr.Blocks() as demo: | |
| with gr.Tab("Run Search"): | |
| gr.Markdown("## π Smart Lead Search Tool with Free Web Scraping") | |
| gr.Markdown(""" | |
| ### π‘ Smart Search Tips: | |
| Try using targeted queries like: | |
| - `marketing agencies in Hyderabad site:linkedin.com` | |
| - `software startups in Bangalore contact us` | |
| - `organic food brands in India site:crunchbase.com` | |
| - `AI companies in Mumbai site:linkedin.com` | |
| Use the preset dropdown or enter your own search string below. | |
| """) | |
| preset_queries = [ | |
| "marketing agencies in Hyderabad site:linkedin.com", | |
| "software startups in Bangalore contact us", | |
| "organic food brands in India site:crunchbase.com", | |
| "AI companies in Mumbai site:linkedin.com", | |
| "top edtech startups in India site:linkedin.com" | |
| ] | |
| preset = gr.Dropdown(choices=preset_queries, label="Choose a Smart Query", interactive=True) | |
| custom_query = gr.Textbox(label="Or Enter Your Custom Search Query") | |
| num_results = gr.Number(label="Number of Results", value=10) | |
| run_button = gr.Button("Run Search") | |
| run_output = gr.Textbox(label="Output") | |
| run_button.click( | |
| fn=run_combined_query, | |
| inputs=[preset, custom_query, num_results], | |
| outputs=run_output | |
| ) | |
| with gr.Tab("View Leads"): | |
| gr.Markdown("## π View, Deduplicate, and Download Leads") | |
| view_button = gr.Button("π Refresh Leads") | |
| lead_table = gr.HTML(visible=True) | |
| view_button.click(view_leads, outputs=lead_table) | |
| remove_button = gr.Button("π©Ή Remove Duplicates") | |
| remove_output = gr.HTML(visible=True) | |
| remove_button.click(fn=remove_and_return_html, outputs=remove_output) | |
| download_button = gr.Button("β¬οΈ Download Leads") | |
| download_file = gr.File(label="Download Excel", visible=True) | |
| download_button.click(fn=download_leads, outputs=download_file) | |
| if __name__ == "__main__": | |
| demo.launch(server_name="0.0.0.0", server_port=7860) | |