File size: 1,715 Bytes
3a14338 |
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 |
import modal
from duckduckgo_search import DDGS
from bs4 import BeautifulSoup
import requests
# Create a Modal app
app = modal.App("healthmate-clinic-lookup")
# Define the base image with required dependencies
image = modal.Image.debian_slim().pip_install(
"duckduckgo_search",
"beautifulsoup4",
"requests",
"fastapi[standard]"
)
@app.function(image=image)
@modal.fastapi_endpoint()
def search_clinics(city: str) -> list:
"""
Search for clinics near the specified city using DuckDuckGo.
Returns a list of dictionaries containing clinic information.
"""
if not city:
return [{"error": "Please provide a city name"}]
try:
# Initialize DuckDuckGo search
with DDGS() as ddgs:
# Search for clinics
search_query = f"top medical clinics near {city}"
results = list(ddgs.text(search_query, max_results=3))
if not results:
return [{"error": f"No clinics found near {city}"}]
# Process and format results
clinics = []
for result in results:
clinic_info = {
"name": result.get("title", "Unknown Clinic"),
"link": result.get("link", "#"),
"description": result.get("body", "No description available")
}
clinics.append(clinic_info)
return clinics
except Exception as e:
return [{"error": f"Error searching for clinics: {str(e)}"}]
@app.local_entrypoint()
def main():
# Test the function locally
results = search_clinics.remote("San Francisco")
print(results) |