# app.py import gradio as gr import requests import google.generativeai as genai import json import os import re # Configurazione da variabili d'ambiente GEMINI_KEY = os.getenv("GEMINI") UNSPLASH_KEY = os.getenv("UNSPLASH_ACCESS") WEATHER_KEY = os.getenv("OPENWEATHER") # Inizializzazione Gemini genai.configure(api_key=GEMINI_KEY) model = genai.GenerativeModel('gemini-pro') CSS = """ body { font-family: 'Arial', sans-serif; background: #f5f7fa; margin: 0; } .travel-container { max-width: 1200px; margin: 0 auto; padding: 20px; } .header { text-align: center; color: #2d3436; margin-bottom: 30px; } .section { background: white; padding: 20px; border-radius: 15px; margin-bottom: 20px; box-shadow: 0 2px 4px rgba(0,0,0,0.1); } .card { border: 1px solid #e0e0e0; padding: 15px; margin: 10px 0; border-radius: 8px; transition: transform 0.2s; } .card:hover { transform: translateY(-3px); } .gallery { display: flex; flex-wrap: wrap; gap: 10px; margin: 15px 0; } .gallery img { width: 30%; flex-grow: 1; border-radius: 8px; height: 200px; object-fit: cover; } .weather-widget { background: #e3f2fd !important; padding: 15px !important; } .price-tag { color: #2e7d32; font-weight: bold; } .reasons-list { padding-left: 20px; color: #666; } .loading { text-align: center; padding: 30px; color: #555; } .error { background: #ffebee; color: #d32f2f; padding: 20px; border-radius: 8px; } """ def get_weather(city): try: url = "http://api.openweathermap.org/data/2.5/weather" params = { "q": city, "appid": WEATHER_KEY, "units": "metric", "lang": "it" } response = requests.get(url, params=params, timeout=10) data = response.json() return f"""
""" except Exception as e: print(f"Errore meteo: {str(e)}") return "" def get_city_photos(city): try: url = "https://api.unsplash.com/search/photos" headers = {"Authorization": f"Client-ID {UNSPLASH_KEY}"} params = {"query": f"{city} city", "per_page": 3} response = requests.get(url, headers=headers, params=params, timeout=10) photos = [img['urls']['regular'] for img in response.json()['results']] return f"""📍 {item.get('address', 'Indirizzo non disponibile')}
💰 {item.get('price_range', '€')}
{item.get('description', '')}
✔️ {r}
" for r in item.get('reasons', [])])}💡 {item.get('tip', '')}
Nessun risultato trovato
'}{str(e)}
Prova a ricaricare la pagina o riprova più tardi