Spaces:
Sleeping
Sleeping
| 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() | |