Americo commited on
Commit
4e0d3a6
verified
1 Parent(s): bdafc7b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -8
app.py CHANGED
@@ -132,9 +132,10 @@ def validar_plan_de_afiliado(plan: str, practica: str) -> Dict[str, Any]:
132
  }
133
 
134
 
 
135
  APP_NAME = "predoc_app"
136
 
137
- # Definici贸n del agente
138
  root_agent = LlmAgent(
139
  model=LiteLlm(model="openai/gpt-4.1"),
140
  generate_content_config=types.GenerateContentConfig(temperature=0.0),
@@ -146,16 +147,14 @@ root_agent = LlmAgent(
146
 
147
  session_service = InMemorySessionService()
148
 
149
- # Funci贸n principal con state
150
- def respond(message, history, state):
151
- # Inicializamos state si es la primera vez
152
  if state is None:
153
  user_id = str(uuid.uuid4())
154
  session_id = str(uuid.uuid4())
155
  state = {"user_id": user_id, "session_id": session_id}
156
  print(f"馃攧 Nueva sesi贸n: {session_id}")
157
 
158
- # Crear sesi贸n ADK de forma as铆ncrona
159
  async def create_session():
160
  await session_service.create_session(
161
  app_name=APP_NAME,
@@ -206,7 +205,7 @@ def respond(message, history, state):
206
  return event.content.parts[0].text
207
  return "No se obtuvo respuesta."
208
 
209
- # Dispatcher seg煤n tipo de input
210
  if message['text'] != '' and len(message['files']) > 0:
211
  return call_agent_both(message['files'], message['text']), state
212
  elif message['text'] == '' and len(message['files']) > 0:
@@ -216,6 +215,7 @@ def respond(message, history, state):
216
  else:
217
  return "Escribe algo para que pueda contestarte.", state
218
 
219
- # Gradio interface con estado
220
- demo = gr.ChatInterface(fn=respond, title="Agente Revisor", multimodal=True, state=gr.State())
 
221
  demo.launch(debug=True)
 
132
  }
133
 
134
 
135
+
136
  APP_NAME = "predoc_app"
137
 
138
+ # Definir agente ra铆z
139
  root_agent = LlmAgent(
140
  model=LiteLlm(model="openai/gpt-4.1"),
141
  generate_content_config=types.GenerateContentConfig(temperature=0.0),
 
147
 
148
  session_service = InMemorySessionService()
149
 
150
+ # Esta funci贸n se conecta a ChatInterface
151
+ def wrapped_respond(message, history, state=None):
 
152
  if state is None:
153
  user_id = str(uuid.uuid4())
154
  session_id = str(uuid.uuid4())
155
  state = {"user_id": user_id, "session_id": session_id}
156
  print(f"馃攧 Nueva sesi贸n: {session_id}")
157
 
 
158
  async def create_session():
159
  await session_service.create_session(
160
  app_name=APP_NAME,
 
205
  return event.content.parts[0].text
206
  return "No se obtuvo respuesta."
207
 
208
+ # Dispatcher
209
  if message['text'] != '' and len(message['files']) > 0:
210
  return call_agent_both(message['files'], message['text']), state
211
  elif message['text'] == '' and len(message['files']) > 0:
 
215
  else:
216
  return "Escribe algo para que pueda contestarte.", state
217
 
218
+ # Inicializamos demo sin el argumento state
219
+ demo = gr.ChatInterface(fn=wrapped_respond, title="Agente Revisor", multimodal=True)
220
+
221
  demo.launch(debug=True)