patopla commited on
Commit
88d1b70
·
verified ·
1 Parent(s): 38f315e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +84 -17
app.py CHANGED
@@ -16,11 +16,40 @@ class BasicAgent:
16
  def __init__(self):
17
  print("BasicAgent initialized.")
18
  self.analizar_historia = AmbiguityClassifier()
 
19
  def __call__(self, question: str) -> str:
20
  print(f"Agent received question (first 50 chars): {question[:50]}...")
21
- fixed_answer = "This is a default answer."
22
- print(f"Agent returning fixed answer: {fixed_answer}")
23
- return fixed_answer
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24
 
25
  def run_and_submit_all( profile: gr.OAuthProfile | None):
26
  """
@@ -146,20 +175,58 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
146
  # --- Build Gradio Interface using Blocks ---
147
  with gr.Blocks() as demo:
148
  gr.Markdown("# Basic Agent Evaluation Runner")
149
- gr.Markdown(
150
- """
151
- **Instructions:**
152
-
153
- 1. Please clone this space, then modify the code to define your agent's logic, the tools, the necessary packages, etc ...
154
- 2. Log in to your Hugging Face account using the button below. This uses your HF username for submission.
155
- 3. Click 'Run Evaluation & Submit All Answers' to fetch questions, run your agent, submit answers, and see the score.
156
-
157
- ---
158
- **Disclaimers:**
159
- Once clicking on the "submit button, it can take quite some time ( this is the time for the agent to go through all the questions).
160
- This space provides a basic setup and is intentionally sub-optimal to encourage you to develop your own, more robust solution. For instance for the delay process of the submit button, a solution could be to cache the answers and submit in a seperate action or even to answer the questions in async.
161
- """
162
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
163
 
164
  gr.LoginButton()
165
 
 
16
  def __init__(self):
17
  print("BasicAgent initialized.")
18
  self.analizar_historia = AmbiguityClassifier()
19
+
20
  def __call__(self, question: str) -> str:
21
  print(f"Agent received question (first 50 chars): {question[:50]}...")
22
+ try:
23
+ resultado = self.analizar_historia(question)
24
+
25
+ # Formatear la respuesta
26
+ respuesta = []
27
+ if resultado["tiene_ambiguedad"]:
28
+ respuesta.append("Se encontraron las siguientes ambigüedades:")
29
+
30
+ if resultado["ambiguedad_lexica"]:
31
+ respuesta.append("\nAmbigüedades léxicas:")
32
+ for amb in resultado["ambiguedad_lexica"]:
33
+ respuesta.append(f"- {amb}")
34
+
35
+ if resultado["ambiguedad_sintactica"]:
36
+ respuesta.append("\nAmbigüedades sintácticas:")
37
+ for amb in resultado["ambiguedad_sintactica"]:
38
+ respuesta.append(f"- {amb}")
39
+
40
+ respuesta.append(f"\nScore de ambigüedad: {resultado['score_ambiguedad']}")
41
+ respuesta.append("\nSugerencias de mejora:")
42
+ for sug in resultado["sugerencias"]:
43
+ respuesta.append(f"- {sug}")
44
+ else:
45
+ respuesta.append("No se encontraron ambigüedades en la historia de usuario.")
46
+ respuesta.append(f"Score de ambigüedad: {resultado['score_ambiguedad']}")
47
+
48
+ return "\n".join(respuesta)
49
+ except Exception as e:
50
+ error_msg = f"Error analizando la historia: {str(e)}"
51
+ print(error_msg)
52
+ return error_msg
53
 
54
  def run_and_submit_all( profile: gr.OAuthProfile | None):
55
  """
 
175
  # --- Build Gradio Interface using Blocks ---
176
  with gr.Blocks() as demo:
177
  gr.Markdown("# Basic Agent Evaluation Runner")
178
+ gr.Markdown("""
179
+ # 🔍 Detector de Ambigüedades en Historias de Usuario
180
+
181
+ Esta herramienta analiza historias de usuario en busca de ambigüedades léxicas y sintácticas,
182
+ proporcionando sugerencias para mejorarlas.
183
+
184
+ ## 📝 Instrucciones:
185
+ 1. Ingrese una historia de usuario en el campo de texto
186
+ 2. Haga clic en "Analizar"
187
+ 3. Revise los resultados y las sugerencias de mejora
188
+
189
+ """)
190
+
191
+ with gr.Tab("Análisis Individual"):
192
+ input_text = gr.Textbox(
193
+ label="Historia de Usuario",
194
+ placeholder="Como usuario quiero...",
195
+ lines=3
196
+ )
197
+ analyze_btn = gr.Button("Analizar")
198
+ output = gr.Textbox(
199
+ label="Resultados del Análisis",
200
+ lines=10
201
+ )
202
+ analyze_btn.click(
203
+ analyze_user_story,
204
+ inputs=[input_text],
205
+ outputs=[output]
206
+ )
207
+
208
+ with gr.Tab("Análisis Múltiple"):
209
+ input_stories = gr.Textbox(
210
+ label="Historias de Usuario (una por línea)",
211
+ placeholder="Como usuario quiero...\nComo administrador necesito...",
212
+ lines=5
213
+ )
214
+ analyze_multi_btn = gr.Button("Analizar Todas")
215
+ output_json = gr.JSON(label="Resultados del Análisis")
216
+ analyze_multi_btn.click(
217
+ analyze_multiple_stories,
218
+ inputs=[input_stories],
219
+ outputs=[output_json]
220
+ )
221
+
222
+ gr.Markdown("""
223
+ ## 🚀 Ejemplos de Uso
224
+
225
+ Pruebe con estas historias de usuario:
226
+ - Como usuario quiero un sistema rápido y eficiente para gestionar mis tareas
227
+ - El sistema debe permitir exportar varios tipos de archivos
228
+ - Como administrador necesito acceder fácilmente a los reportes
229
+ """)
230
 
231
  gr.LoginButton()
232