Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -27,7 +27,7 @@ class AIEvaluationForm:
|
|
27 |
components = {}
|
28 |
|
29 |
with gr.Group():
|
30 |
-
gr.Markdown("##
|
31 |
gr.Markdown("*Please provide basic information about the AI system being evaluated.*")
|
32 |
|
33 |
components['name'] = gr.Textbox(
|
@@ -61,7 +61,7 @@ class AIEvaluationForm:
|
|
61 |
info="Primary category of the AI system"
|
62 |
)
|
63 |
|
64 |
-
components['
|
65 |
choices=[
|
66 |
"Text",
|
67 |
"Image",
|
@@ -71,10 +71,10 @@ class AIEvaluationForm:
|
|
71 |
],
|
72 |
label="Input modalities (select all that apply)",
|
73 |
value=["Text"],
|
74 |
-
info="
|
75 |
)
|
76 |
|
77 |
-
components['
|
78 |
choices=[
|
79 |
"Text",
|
80 |
"Image",
|
@@ -84,7 +84,7 @@ class AIEvaluationForm:
|
|
84 |
],
|
85 |
label="Output Modalities (select all that apply)",
|
86 |
value=["Text"],
|
87 |
-
info="
|
88 |
)
|
89 |
|
90 |
return list(components.values()), components
|
@@ -163,13 +163,13 @@ class AIEvaluationForm:
|
|
163 |
|
164 |
# Determine source type based on content
|
165 |
if line.startswith('http'):
|
166 |
-
source_type = "
|
167 |
name = line.split('/')[-1] if '/' in line else line
|
168 |
elif 'internal' in line.lower() or 'proprietary' in line.lower():
|
169 |
-
source_type = "
|
170 |
name = line
|
171 |
else:
|
172 |
-
source_type = "
|
173 |
name = line
|
174 |
|
175 |
sources.append({
|
@@ -179,6 +179,17 @@ class AIEvaluationForm:
|
|
179 |
})
|
180 |
|
181 |
return sources
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
182 |
|
183 |
def generate_scorecard(self, *args) -> Tuple[Dict, str]:
|
184 |
"""Generate scorecard JSON from form inputs"""
|
@@ -187,10 +198,9 @@ class AIEvaluationForm:
|
|
187 |
for i, arg in enumerate(args[:10]): # Print first 10 for debugging
|
188 |
print(f"Arg {i}: {type(arg)} = {arg}")
|
189 |
|
190 |
-
# Extract system info (first
|
191 |
-
|
192 |
-
|
193 |
-
remaining_args = list(args[num_args:])
|
194 |
|
195 |
# Build metadata
|
196 |
metadata = {
|
@@ -308,7 +318,7 @@ class AIEvaluationForm:
|
|
308 |
|
309 |
# Header
|
310 |
gr.Markdown("""
|
311 |
-
#
|
312 |
|
313 |
This comprehensive evaluation form helps you assess AI systems across multiple dimensions including bias,
|
314 |
cultural sensitivity, environmental impact, privacy, and more. Complete the sections relevant to your system
|
@@ -326,17 +336,17 @@ class AIEvaluationForm:
|
|
326 |
|
327 |
# Generate button and outputs
|
328 |
with gr.Group():
|
329 |
-
gr.Markdown("##
|
330 |
|
331 |
with gr.Row():
|
332 |
generate_btn = gr.Button(
|
333 |
-
"
|
334 |
variant="primary",
|
335 |
size="lg",
|
336 |
scale=2
|
337 |
)
|
338 |
clear_btn = gr.Button(
|
339 |
-
"
|
340 |
variant="secondary",
|
341 |
scale=1
|
342 |
)
|
@@ -346,7 +356,7 @@ class AIEvaluationForm:
|
|
346 |
|
347 |
# Outputs
|
348 |
with gr.Group():
|
349 |
-
gr.Markdown("###
|
350 |
|
351 |
with gr.Row():
|
352 |
json_output = gr.JSON(
|
@@ -359,13 +369,6 @@ class AIEvaluationForm:
|
|
359 |
label="Download Scorecard",
|
360 |
visible=False
|
361 |
)
|
362 |
-
download_btn = gr.Button(
|
363 |
-
"πΎ Download JSON",
|
364 |
-
visible=False,
|
365 |
-
variant="secondary"
|
366 |
-
)
|
367 |
-
# Hidden HTML component for triggering downloads
|
368 |
-
download_html = gr.HTML(visible=False)
|
369 |
|
370 |
# Event handlers
|
371 |
all_inputs = system_inputs + eval_inputs
|
@@ -386,25 +389,9 @@ class AIEvaluationForm:
|
|
386 |
|
387 |
return (
|
388 |
scorecard, # JSON display
|
389 |
-
gr.File(value=filename, visible=True)
|
390 |
-
gr.Button(visible=True), # Show download button
|
391 |
-
gr.HTML(visible=False) # Hidden HTML for download trigger
|
392 |
)
|
393 |
-
|
394 |
-
def trigger_download():
|
395 |
-
"""Trigger file download via JavaScript"""
|
396 |
-
return gr.HTML("""
|
397 |
-
<script>
|
398 |
-
// Find the download link and click it
|
399 |
-
setTimeout(() => {
|
400 |
-
const downloadLinks = document.querySelectorAll('a[download]');
|
401 |
-
if (downloadLinks.length > 0) {
|
402 |
-
downloadLinks[downloadLinks.length - 1].click();
|
403 |
-
}
|
404 |
-
}, 100);
|
405 |
-
</script>
|
406 |
-
""", visible=False)
|
407 |
-
|
408 |
def clear_form():
|
409 |
"""Clear all form inputs"""
|
410 |
return [None] * len(all_inputs)
|
@@ -413,16 +400,10 @@ class AIEvaluationForm:
|
|
413 |
generate_btn.click(
|
414 |
fn=generate_with_progress,
|
415 |
inputs=all_inputs,
|
416 |
-
outputs=[json_output, download_file
|
417 |
show_progress="full"
|
418 |
)
|
419 |
|
420 |
-
# Wire up download button to trigger download
|
421 |
-
download_btn.click(
|
422 |
-
fn=trigger_download,
|
423 |
-
outputs=download_html
|
424 |
-
)
|
425 |
-
|
426 |
clear_btn.click(
|
427 |
fn=clear_form,
|
428 |
outputs=all_inputs
|
@@ -430,8 +411,8 @@ class AIEvaluationForm:
|
|
430 |
|
431 |
# Add example data button
|
432 |
with gr.Group():
|
433 |
-
gr.Markdown("###
|
434 |
-
example_btn = gr.Button("
|
435 |
|
436 |
def load_example():
|
437 |
"""Load example data for StarCoder2-like system"""
|
@@ -440,8 +421,8 @@ class AIEvaluationForm:
|
|
440 |
"BigCode", # provider
|
441 |
"https://huggingface.co/bigcode/starcoder2-15b", # url
|
442 |
"Generative Model", # type
|
443 |
-
["Text"], # input modalities
|
444 |
-
["Text"]
|
445 |
]
|
446 |
# Add default values for evaluation sections (all N/A initially)
|
447 |
remaining_defaults = []
|
@@ -459,28 +440,21 @@ class AIEvaluationForm:
|
|
459 |
fn=load_example,
|
460 |
outputs=all_inputs
|
461 |
)
|
|
|
462 |
with gr.Group():
|
463 |
-
gr.Markdown("###
|
464 |
uploaded_file = gr.File(label="Upload JSON File", file_types=[".json"])
|
465 |
uploaded_preview = gr.JSON(label="Preview of Uploaded Content")
|
466 |
-
uploaded_file.change(fn=load_uploaded_json, inputs=uploaded_file, outputs=uploaded_preview)
|
467 |
|
468 |
gr.Markdown("""
|
469 |
-
###
|
470 |
Once downloaded, you can contribute by submitting a pull request to [Eval Cards GitHub](https://github.com/evaleval/Eval_Cards).
|
471 |
Place your file in the `submissions/` directory.
|
472 |
""")
|
473 |
|
474 |
return demo
|
475 |
-
|
476 |
-
def load_uploaded_json(file):
|
477 |
-
if file is None:
|
478 |
-
return {}
|
479 |
-
try:
|
480 |
-
with open(file.name, 'r') as f:
|
481 |
-
return json.load(f)
|
482 |
-
except Exception as e:
|
483 |
-
return {"error": str(e)}
|
484 |
|
485 |
def main():
|
486 |
"""Main function to run the application"""
|
@@ -491,9 +465,9 @@ def main():
|
|
491 |
# Create and launch the interface
|
492 |
demo = eval_form.create_interface()
|
493 |
|
494 |
-
print("
|
495 |
-
print(f"
|
496 |
-
print(f"
|
497 |
|
498 |
# Count total questions
|
499 |
total_questions = sum(
|
@@ -501,7 +475,7 @@ def main():
|
|
501 |
for section in eval_form.template.values()
|
502 |
for subsection in section.values()
|
503 |
)
|
504 |
-
print(f"
|
505 |
|
506 |
demo.launch(
|
507 |
ssr_mode=False,
|
@@ -512,10 +486,10 @@ def main():
|
|
512 |
)
|
513 |
|
514 |
except FileNotFoundError as e:
|
515 |
-
print(f"
|
516 |
print("Please ensure 'questions.yaml' exists in the current directory.")
|
517 |
except Exception as e:
|
518 |
-
print(f"
|
519 |
|
520 |
if __name__ == "__main__":
|
521 |
main()
|
|
|
27 |
components = {}
|
28 |
|
29 |
with gr.Group():
|
30 |
+
gr.Markdown("## System Information")
|
31 |
gr.Markdown("*Please provide basic information about the AI system being evaluated.*")
|
32 |
|
33 |
components['name'] = gr.Textbox(
|
|
|
61 |
info="Primary category of the AI system"
|
62 |
)
|
63 |
|
64 |
+
components['input_modalities'] = gr.CheckboxGroup(
|
65 |
choices=[
|
66 |
"Text",
|
67 |
"Image",
|
|
|
71 |
],
|
72 |
label="Input modalities (select all that apply)",
|
73 |
value=["Text"],
|
74 |
+
info="Input modalities supported by the system"
|
75 |
)
|
76 |
|
77 |
+
components['output_modalities'] = gr.CheckboxGroup(
|
78 |
choices=[
|
79 |
"Text",
|
80 |
"Image",
|
|
|
84 |
],
|
85 |
label="Output Modalities (select all that apply)",
|
86 |
value=["Text"],
|
87 |
+
info="Output modalities supported by the system"
|
88 |
)
|
89 |
|
90 |
return list(components.values()), components
|
|
|
163 |
|
164 |
# Determine source type based on content
|
165 |
if line.startswith('http'):
|
166 |
+
source_type = "Web"
|
167 |
name = line.split('/')[-1] if '/' in line else line
|
168 |
elif 'internal' in line.lower() or 'proprietary' in line.lower():
|
169 |
+
source_type = "Internal"
|
170 |
name = line
|
171 |
else:
|
172 |
+
source_type = "Document"
|
173 |
name = line
|
174 |
|
175 |
sources.append({
|
|
|
179 |
})
|
180 |
|
181 |
return sources
|
182 |
+
|
183 |
+
def load_uploaded_json(self, file):
|
184 |
+
"""Load JSON from uploaded file"""
|
185 |
+
if file is None:
|
186 |
+
return {}
|
187 |
+
try:
|
188 |
+
with open(file.name, 'r') as f:
|
189 |
+
return json.load(f)
|
190 |
+
except Exception as e:
|
191 |
+
return {"error": str(e)}
|
192 |
+
|
193 |
|
194 |
def generate_scorecard(self, *args) -> Tuple[Dict, str]:
|
195 |
"""Generate scorecard JSON from form inputs"""
|
|
|
198 |
for i, arg in enumerate(args[:10]): # Print first 10 for debugging
|
199 |
print(f"Arg {i}: {type(arg)} = {arg}")
|
200 |
|
201 |
+
# Extract system info (first 6 arguments)
|
202 |
+
name, provider, url, sys_type, inp_modalities, out_modalities = args[:6]
|
203 |
+
remaining_args = list(args[6:])
|
|
|
204 |
|
205 |
# Build metadata
|
206 |
metadata = {
|
|
|
318 |
|
319 |
# Header
|
320 |
gr.Markdown("""
|
321 |
+
# AI System Evaluation Scorecard
|
322 |
|
323 |
This comprehensive evaluation form helps you assess AI systems across multiple dimensions including bias,
|
324 |
cultural sensitivity, environmental impact, privacy, and more. Complete the sections relevant to your system
|
|
|
336 |
|
337 |
# Generate button and outputs
|
338 |
with gr.Group():
|
339 |
+
gr.Markdown("## Generate Scorecard")
|
340 |
|
341 |
with gr.Row():
|
342 |
generate_btn = gr.Button(
|
343 |
+
"Generate Evaluation Scorecard",
|
344 |
variant="primary",
|
345 |
size="lg",
|
346 |
scale=2
|
347 |
)
|
348 |
clear_btn = gr.Button(
|
349 |
+
"Clear Form",
|
350 |
variant="secondary",
|
351 |
scale=1
|
352 |
)
|
|
|
356 |
|
357 |
# Outputs
|
358 |
with gr.Group():
|
359 |
+
gr.Markdown("### Generated Scorecard")
|
360 |
|
361 |
with gr.Row():
|
362 |
json_output = gr.JSON(
|
|
|
369 |
label="Download Scorecard",
|
370 |
visible=False
|
371 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
372 |
|
373 |
# Event handlers
|
374 |
all_inputs = system_inputs + eval_inputs
|
|
|
389 |
|
390 |
return (
|
391 |
scorecard, # JSON display
|
392 |
+
gr.File(value=filename, visible=True) # File for download
|
|
|
|
|
393 |
)
|
394 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
395 |
def clear_form():
|
396 |
"""Clear all form inputs"""
|
397 |
return [None] * len(all_inputs)
|
|
|
400 |
generate_btn.click(
|
401 |
fn=generate_with_progress,
|
402 |
inputs=all_inputs,
|
403 |
+
outputs=[json_output, download_file],
|
404 |
show_progress="full"
|
405 |
)
|
406 |
|
|
|
|
|
|
|
|
|
|
|
|
|
407 |
clear_btn.click(
|
408 |
fn=clear_form,
|
409 |
outputs=all_inputs
|
|
|
411 |
|
412 |
# Add example data button
|
413 |
with gr.Group():
|
414 |
+
gr.Markdown("### Quick Start")
|
415 |
+
example_btn = gr.Button("Load Example Data", variant="secondary")
|
416 |
|
417 |
def load_example():
|
418 |
"""Load example data for StarCoder2-like system"""
|
|
|
421 |
"BigCode", # provider
|
422 |
"https://huggingface.co/bigcode/starcoder2-15b", # url
|
423 |
"Generative Model", # type
|
424 |
+
["Text"], # input modalities - FIXED: Added missing comma
|
425 |
+
["Text"] # output modalities
|
426 |
]
|
427 |
# Add default values for evaluation sections (all N/A initially)
|
428 |
remaining_defaults = []
|
|
|
440 |
fn=load_example,
|
441 |
outputs=all_inputs
|
442 |
)
|
443 |
+
|
444 |
with gr.Group():
|
445 |
+
gr.Markdown("### Upload Completed Evaluation JSON")
|
446 |
uploaded_file = gr.File(label="Upload JSON File", file_types=[".json"])
|
447 |
uploaded_preview = gr.JSON(label="Preview of Uploaded Content")
|
448 |
+
uploaded_file.change(fn=self.load_uploaded_json, inputs=uploaded_file, outputs=uploaded_preview)
|
449 |
|
450 |
gr.Markdown("""
|
451 |
+
### Submit Your Scorecard to the Eval Cards Repository
|
452 |
Once downloaded, you can contribute by submitting a pull request to [Eval Cards GitHub](https://github.com/evaleval/Eval_Cards).
|
453 |
Place your file in the `submissions/` directory.
|
454 |
""")
|
455 |
|
456 |
return demo
|
457 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
458 |
|
459 |
def main():
|
460 |
"""Main function to run the application"""
|
|
|
465 |
# Create and launch the interface
|
466 |
demo = eval_form.create_interface()
|
467 |
|
468 |
+
print("Launching AI Evaluation Scorecard...")
|
469 |
+
print(f"Loading questions from: {eval_form.template_file}")
|
470 |
+
print(f"Found {len(eval_form.template)} evaluation categories")
|
471 |
|
472 |
# Count total questions
|
473 |
total_questions = sum(
|
|
|
475 |
for section in eval_form.template.values()
|
476 |
for subsection in section.values()
|
477 |
)
|
478 |
+
print(f"Total evaluation questions: {total_questions}")
|
479 |
|
480 |
demo.launch(
|
481 |
ssr_mode=False,
|
|
|
486 |
)
|
487 |
|
488 |
except FileNotFoundError as e:
|
489 |
+
print(f"Error: {e}")
|
490 |
print("Please ensure 'questions.yaml' exists in the current directory.")
|
491 |
except Exception as e:
|
492 |
+
print(f"Unexpected error: {e}")
|
493 |
|
494 |
if __name__ == "__main__":
|
495 |
main()
|