Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| import requests | |
| from bs4 import BeautifulSoup | |
| import time | |
| # Function to scrape Crunchbase for matching companies | |
| def search_companies(service_description, region): | |
| search_url = f"https://www.crunchbase.com/discover/organization.companies?query={service_description} {region}" | |
| headers = {"User-Agent": "Mozilla/5.0"} | |
| try: | |
| response = requests.get(search_url, headers=headers) | |
| if response.status_code != 200: | |
| return f"Error: Unable to fetch data (Status Code: {response.status_code})" | |
| soup = BeautifulSoup(response.text, "html.parser") | |
| # Extract company details | |
| companies = [] | |
| for item in soup.find_all("grid-row", class_="organization"): | |
| name = item.find("profile-name").text if item.find("profile-name") else "Unknown" | |
| industry = item.find("category").text if item.find("category") else "Not listed" | |
| location = item.find("location").text if item.find("location") else "Unknown" | |
| funding = item.find("funding-amount").text if item.find("funding-amount") else "Not available" | |
| companies.append({"Name": name, "Industry": industry, "Location": location, "Funding": funding}) | |
| if len(companies) == 5: # Only get top 5 companies | |
| break | |
| if not companies: | |
| return "No matching companies found. Try refining your search." | |
| # Convert to table format | |
| result = "### Top 5 Matching Companies:\n\n" | |
| result += "| Name | Industry | Location | Funding |\n" | |
| result += "|------|----------|----------|---------|\n" | |
| for c in companies: | |
| result += f"| {c['Name']} | {c['Industry']} | {c['Location']} | {c['Funding']} |\n" | |
| return result | |
| except Exception as e: | |
| return f"An error occurred: {str(e)}" | |
| # Gradio Interface | |
| def search_ui(service_description, region): | |
| return search_companies(service_description, region) | |
| iface = gr.Interface( | |
| fn=search_ui, | |
| inputs=["text", "text"], | |
| outputs="text", | |
| title="Company Finder", | |
| description="Enter your company services description and a region to find the top 5 matching companies from Crunchbase." | |
| ) | |
| # Run the app | |
| if __name__ == "__main__": | |
| iface.launch() | |