Update app.py
#780
by TurismoparalaVida - opened
app.py
CHANGED
|
@@ -1,69 +1,150 @@
|
|
| 1 |
-
from smolagents import CodeAgent,DuckDuckGoSearchTool, HfApiModel,load_tool,tool
|
| 2 |
import datetime
|
| 3 |
-
import requests
|
| 4 |
import pytz
|
| 5 |
import yaml
|
| 6 |
from tools.final_answer import FinalAnswerTool
|
| 7 |
-
|
| 8 |
from Gradio_UI import GradioUI
|
| 9 |
|
| 10 |
-
#
|
|
|
|
|
|
|
|
|
|
| 11 |
@tool
|
| 12 |
-
def
|
| 13 |
-
|
| 14 |
-
|
| 15 |
Args:
|
| 16 |
-
|
| 17 |
-
|
| 18 |
"""
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
@tool
|
| 22 |
def get_current_time_in_timezone(timezone: str) -> str:
|
| 23 |
-
"""
|
|
|
|
| 24 |
Args:
|
| 25 |
-
timezone:
|
| 26 |
"""
|
| 27 |
try:
|
| 28 |
-
# Create timezone object
|
| 29 |
tz = pytz.timezone(timezone)
|
| 30 |
-
# Get current time in that timezone
|
| 31 |
local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")
|
| 32 |
-
return f"
|
| 33 |
except Exception as e:
|
| 34 |
-
return f"Error
|
| 35 |
|
|
|
|
|
|
|
|
|
|
| 36 |
|
| 37 |
final_answer = FinalAnswerTool()
|
| 38 |
-
|
| 39 |
-
# If the agent does not answer, the model is overloaded, please use another model or the following Hugging Face Endpoint that also contains qwen2.5 coder:
|
| 40 |
-
# model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'
|
| 41 |
|
| 42 |
model = HfApiModel(
|
| 43 |
-
max_tokens=2096,
|
| 44 |
-
temperature=0.5,
|
| 45 |
-
model_id='Qwen/Qwen2.5-Coder-32B-Instruct',
|
| 46 |
-
custom_role_conversions=None,
|
| 47 |
)
|
| 48 |
|
| 49 |
-
|
| 50 |
-
# Import tool from Hub
|
| 51 |
-
image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
|
| 52 |
-
|
| 53 |
with open("prompts.yaml", 'r') as stream:
|
| 54 |
prompt_templates = yaml.safe_load(stream)
|
| 55 |
-
|
|
|
|
| 56 |
agent = CodeAgent(
|
| 57 |
model=model,
|
| 58 |
-
tools=[
|
| 59 |
-
|
| 60 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
grammar=None,
|
| 62 |
planning_interval=None,
|
| 63 |
-
name=
|
| 64 |
-
description=
|
| 65 |
prompt_templates=prompt_templates
|
| 66 |
)
|
| 67 |
|
| 68 |
-
|
| 69 |
GradioUI(agent).launch()
|
|
|
|
| 1 |
+
from smolagents import CodeAgent, DuckDuckGoSearchTool, HfApiModel, load_tool, tool
|
| 2 |
import datetime
|
|
|
|
| 3 |
import pytz
|
| 4 |
import yaml
|
| 5 |
from tools.final_answer import FinalAnswerTool
|
|
|
|
| 6 |
from Gradio_UI import GradioUI
|
| 7 |
|
| 8 |
+
# ---------------------------------------------------------------------------
|
| 9 |
+
# HERRAMIENTAS PERSONALIZADAS (TURISMO Y EVENTOS EN ZIPAQUIRÁ)
|
| 10 |
+
# ---------------------------------------------------------------------------
|
| 11 |
+
|
| 12 |
@tool
|
| 13 |
+
def calculate_event_space(asistentes: int, tipo_montaje: str = "auditorio") -> str:
|
| 14 |
+
"""Calcula el espacio recomendado en metros cuadrados y el aforo ideal para eventos o pasadías corporativos.
|
| 15 |
+
|
| 16 |
Args:
|
| 17 |
+
asistentes: Número total de personas/asistentes.
|
| 18 |
+
tipo_montaje: Estilo del montaje ('auditorio', 'banquete', 'escuela' o 'aire_libre').
|
| 19 |
"""
|
| 20 |
+
factores_m2 = {
|
| 21 |
+
"auditorio": 1.2,
|
| 22 |
+
"banquete": 2.0,
|
| 23 |
+
"escuela": 1.8,
|
| 24 |
+
"aire_libre": 2.5
|
| 25 |
+
}
|
| 26 |
+
factor = factores_m2.get(tipo_montaje.lower(), 1.5)
|
| 27 |
+
area_requerida = asistentes * factor
|
| 28 |
+
|
| 29 |
+
return (
|
| 30 |
+
f"--- CÁLCULO DE ESPACIO PARA EVENTOS ---\n"
|
| 31 |
+
f"• Asistentes: {asistentes} personas\n"
|
| 32 |
+
f"• Estilo de montaje: {tipo_montaje.capitalize()}\n"
|
| 33 |
+
f"• Área mínima recomendada: {area_requerida:.1f} m²\n"
|
| 34 |
+
f"• Recomendación local: Para grupos de {asistentes} personas, los salones y espacios al aire libre de Zipaquirá se adaptan perfectamente."
|
| 35 |
+
)
|
| 36 |
+
|
| 37 |
+
@tool
|
| 38 |
+
def create_event_proposal(nombre_empresa: str, asistentes: int, duracion_dias: int = 1, incluir_catedral: bool = True) -> str:
|
| 39 |
+
"""Genera una propuesta inicial de presupuesto y paquete corporativo/turístico para un grupo en Zipaquirá.
|
| 40 |
+
|
| 41 |
+
Args:
|
| 42 |
+
nombre_empresa: Nombre de la empresa o grupo organizador.
|
| 43 |
+
asistentes: Número de asistentes.
|
| 44 |
+
duracion_dias: Duración de la estancia o evento en días.
|
| 45 |
+
incluir_catedral: Si se debe incluir el recorrido guiado en la Catedral de Sal.
|
| 46 |
+
"""
|
| 47 |
+
costo_base_persona_dia = 90000 # Alimentación, espacio y logística local
|
| 48 |
+
costo_catedral = 60000 if incluir_catedral else 0
|
| 49 |
+
|
| 50 |
+
costo_por_persona = (costo_base_persona_dia * duracion_dias) + costo_catedral
|
| 51 |
+
total_estimado = costo_por_persona * asistentes
|
| 52 |
+
|
| 53 |
+
return (
|
| 54 |
+
f"--- PROPUESTA TURÍSTICA Y DE EVENTOS: {nombre_empresa.upper()} ---\n"
|
| 55 |
+
f"• Participantes: {asistentes}\n"
|
| 56 |
+
f"• Duración: {duracion_dias} día(s)\n"
|
| 57 |
+
f"• Incluye Catedral de Sal: {'Sí' if incluir_catedral else 'No'}\n"
|
| 58 |
+
f"• Tarifa por persona estimada: ${costo_por_persona:,} COP\n"
|
| 59 |
+
f"---------------------------------------------------\n"
|
| 60 |
+
f"PRESUPUESTO TOTAL ESTIMADO: ${total_estimado:,} COP"
|
| 61 |
+
)
|
| 62 |
+
|
| 63 |
+
@tool
|
| 64 |
+
def create_event_agenda(titulo_evento: str, hora_inicio: str = "08:00") -> str:
|
| 65 |
+
"""Genera una agenda cronológica sugerida para un pasadía corporativo/turístico en Zipaquirá.
|
| 66 |
+
|
| 67 |
+
Args:
|
| 68 |
+
titulo_evento: Título o propósito del pasadía/evento.
|
| 69 |
+
hora_inicio: Hora de inicio en formato HH:MM (ejemplo: '08:00').
|
| 70 |
+
"""
|
| 71 |
+
return (
|
| 72 |
+
f"--- AGENDA SUGERIDA: {titulo_evento} ---\n"
|
| 73 |
+
f"• {hora_inicio} - Llegada a Zipaquirá y Coffe Break de bienvenida (productos artesanales).\n"
|
| 74 |
+
f"• 09:30 - Recorrido guiado por la Catedral de Sal (Experiencia de origen y patrimonio).\n"
|
| 75 |
+
f"• 12:30 - Almuerzo gastronómico local en el centro histórico.\n"
|
| 76 |
+
f"• 14:30 - Actividad de integración / Team Building temático.\n"
|
| 77 |
+
f"• 16:30 - Cierre del evento, recorrido por la Plaza Mayor y retorno."
|
| 78 |
+
)
|
| 79 |
+
|
| 80 |
+
@tool
|
| 81 |
+
def recommend_team_building(objetivo: str, entorno: str = "mixto") -> str:
|
| 82 |
+
"""Recomienda actividades de integración y turismo con propósito de acuerdo con el objetivo del equipo.
|
| 83 |
+
|
| 84 |
+
Args:
|
| 85 |
+
objetivo: Meta del equipo ('liderazgo', 'trabajo_en_equipo', 'bienestar', 'comunicacion').
|
| 86 |
+
entorno: Preferencia del espacio ('interior', 'al_aire_libre' o 'mixto').
|
| 87 |
+
"""
|
| 88 |
+
recomendaciones = {
|
| 89 |
+
"liderazgo": "Desafío Minero en Zipaquirá: Dinámicas de orientación y toma de decisiones en rutas históricas.",
|
| 90 |
+
"trabajo_en_equipo": "Taller de Alfarería y Escultura en Sal: Creación colectiva de símbolos con artesanos locales.",
|
| 91 |
+
"bienestar": "Caminata de conexión ambiental por los senderos ecológicos y pausa activa con gastronomía consciente.",
|
| 92 |
+
"comunicacion": "Rally de Pistas en el Centro Histórico de Zipaquirá: Descubriendo la historia a través del trabajo coordinado."
|
| 93 |
+
}
|
| 94 |
+
|
| 95 |
+
actividad = recomendaciones.get(objetivo.lower(), "Experiencia integradora en la Plaza Mayor y talleres artísticos comunitarios.")
|
| 96 |
+
return f"Recomendación para objetivo ({objetivo}) en entorno ({entorno}):\n👉 {actividad}"
|
| 97 |
|
| 98 |
@tool
|
| 99 |
def get_current_time_in_timezone(timezone: str) -> str:
|
| 100 |
+
"""Obtiene la hora local actual en una zona horaria específica.
|
| 101 |
+
|
| 102 |
Args:
|
| 103 |
+
timezone: Zona horaria en formato válido (ejemplo: 'America/Bogota').
|
| 104 |
"""
|
| 105 |
try:
|
|
|
|
| 106 |
tz = pytz.timezone(timezone)
|
|
|
|
| 107 |
local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")
|
| 108 |
+
return f"La hora local actual en {timezone} es: {local_time}"
|
| 109 |
except Exception as e:
|
| 110 |
+
return f"Error al obtener la hora para '{timezone}': {str(e)}"
|
| 111 |
|
| 112 |
+
# ---------------------------------------------------------------------------
|
| 113 |
+
# CONFIGURACIÓN E INSTANCIACIÓN
|
| 114 |
+
# ---------------------------------------------------------------------------
|
| 115 |
|
| 116 |
final_answer = FinalAnswerTool()
|
| 117 |
+
search_tool = DuckDuckGoSearchTool()
|
|
|
|
|
|
|
| 118 |
|
| 119 |
model = HfApiModel(
|
| 120 |
+
max_tokens=2096,
|
| 121 |
+
temperature=0.5,
|
| 122 |
+
model_id='Qwen/Qwen2.5-Coder-32B-Instruct',
|
| 123 |
+
custom_role_conversions=None,
|
| 124 |
)
|
| 125 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 126 |
with open("prompts.yaml", 'r') as stream:
|
| 127 |
prompt_templates = yaml.safe_load(stream)
|
| 128 |
+
|
| 129 |
+
# Agente unificado con la estructura solicitada
|
| 130 |
agent = CodeAgent(
|
| 131 |
model=model,
|
| 132 |
+
tools=[
|
| 133 |
+
final_answer,
|
| 134 |
+
search_tool,
|
| 135 |
+
create_event_proposal,
|
| 136 |
+
calculate_event_space,
|
| 137 |
+
create_event_agenda,
|
| 138 |
+
recommend_team_building,
|
| 139 |
+
get_current_time_in_timezone
|
| 140 |
+
],
|
| 141 |
+
max_steps=8,
|
| 142 |
+
verbosity_level=2,
|
| 143 |
grammar=None,
|
| 144 |
planning_interval=None,
|
| 145 |
+
name="AgenteEventosYTurismoZipaquira",
|
| 146 |
+
description="Agente especializado en cotizar, planificar espacios, diseñar agendas y recomendar actividades de integración para eventos de Turismo para la Vida en Zipaquirá.",
|
| 147 |
prompt_templates=prompt_templates
|
| 148 |
)
|
| 149 |
|
|
|
|
| 150 |
GradioUI(agent).launch()
|