File size: 2,286 Bytes
e3f5d53
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
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()