File size: 2,014 Bytes
1b7492d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ea76e26
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
import requests
import gradio as gr

# API base URL
BASE_URL = "https://www.zefix.admin.ch/ZefixPublicREST/api/v1"

def search_companies(service_description):
    """
    Search for companies in Geneva based on a service description.
    Returns the top 5 matching companies.
    """
    try:
        # Step 1: Search for companies by name or description
        response = requests.get(f"{BASE_URL}/companies", params={"name": service_description})
        if response.status_code != 200:
            return f"Error: Unable to fetch data (Status Code: {response.status_code})"

        # Step 2: Filter companies located in Geneva
        companies = response.json()
        geneva_companies = [
            company for company in companies
            if company.get("legalSeat", "").lower() == "Genève"  # "Genève" is French for Geneva
        ]

        # Step 3: Limit results to top 5
        top_5_companies = geneva_companies[:5]

        # Step 4: Format the results
        if not top_5_companies:
            return "No matching companies found in Geneva."

        result = "Top 5 Matching Companies in Geneva:\n\n"
        for company in top_5_companies:
            result += (
                f"Name: {company.get('name', 'N/A')}\n"
                f"CHID: {company.get('chid', 'N/A')}\n"
                f"UID: {company.get('uid', 'N/A')}\n"
                f"Legal Seat: {company.get('legalSeat', 'N/A')}\n"
                f"Registry of Commerce: {company.get('registryOfCommerce', 'N/A')}\n\n"
            )
        return result

    except Exception as e:
        return f"An error occurred: {str(e)}"

# Gradio Interface
interface = gr.Interface(
    fn=search_companies,
    inputs=gr.Textbox(label="Enter Company Service Description"),
    outputs=gr.Textbox(label="Top 5 Matching Companies in Geneva"),
    title="Geneva Company Search",
    description="Enter a company service description to find the top 5 matching companies in Geneva."
)

# Launch the Gradio app
interface.launch()