Spaces:
Runtime error
Runtime error
Commit
·
ae88819
1
Parent(s):
bc41f37
updated interface in brainstorm
Browse files- src/notebooks/brainstorm4.ipynb +44 -99
src/notebooks/brainstorm4.ipynb
CHANGED
@@ -383,20 +383,20 @@
|
|
383 |
},
|
384 |
{
|
385 |
"cell_type": "code",
|
386 |
-
"execution_count":
|
387 |
"metadata": {},
|
388 |
"outputs": [
|
389 |
{
|
390 |
"name": "stderr",
|
391 |
"output_type": "stream",
|
392 |
"text": [
|
393 |
-
"/var/folders/lx/3ksh07r96gn2v7b8mb__3mpc0000gn/T/ipykernel_13584/
|
394 |
" upload_template_btn = gr.UploadButton(label=\"Upload Template File\", file_types = ['.csv'], live=True, file_count = \"single\")\n",
|
395 |
-
"/var/folders/lx/3ksh07r96gn2v7b8mb__3mpc0000gn/T/ipykernel_13584/
|
396 |
" upload_source_button = gr.UploadButton(label=\"Upload Source File\", file_types = ['.csv'], live=True, file_count = \"single\")\n",
|
397 |
-
"/Users/andybryant/Desktop/projects/zero-mapper/venv/lib/python3.9/site-packages/gradio/utils.py:841: UserWarning: Expected 1 arguments for function <function generate_code at
|
398 |
" warnings.warn(\n",
|
399 |
-
"/Users/andybryant/Desktop/projects/zero-mapper/venv/lib/python3.9/site-packages/gradio/utils.py:845: UserWarning: Expected at least 1 arguments for function <function generate_code at
|
400 |
" warnings.warn(\n"
|
401 |
]
|
402 |
},
|
@@ -404,7 +404,7 @@
|
|
404 |
"name": "stdout",
|
405 |
"output_type": "stream",
|
406 |
"text": [
|
407 |
-
"Running on local URL: http://127.0.0.1:
|
408 |
"\n",
|
409 |
"To create a public link, set `share=True` in `launch()`.\n"
|
410 |
]
|
@@ -412,7 +412,7 @@
|
|
412 |
{
|
413 |
"data": {
|
414 |
"text/html": [
|
415 |
-
"<div><iframe src=\"http://127.0.0.1:
|
416 |
],
|
417 |
"text/plain": [
|
418 |
"<IPython.core.display.HTML object>"
|
@@ -425,28 +425,15 @@
|
|
425 |
"data": {
|
426 |
"text/plain": []
|
427 |
},
|
428 |
-
"execution_count":
|
429 |
"metadata": {},
|
430 |
"output_type": "execute_result"
|
431 |
-
},
|
432 |
-
{
|
433 |
-
"name": "stderr",
|
434 |
-
"output_type": "stream",
|
435 |
-
"text": [
|
436 |
-
"/Users/andybryant/Desktop/projects/zero-mapper/venv/lib/python3.9/site-packages/gradio/helpers.py:735: UserWarning: Unexpected argument. Filling with None.\n",
|
437 |
-
" warnings.warn(\"Unexpected argument. Filling with None.\")\n"
|
438 |
-
]
|
439 |
}
|
440 |
],
|
441 |
"source": [
|
442 |
"def _sanitize_python_output(text: str):\n",
|
443 |
" _, after = text.split(\"```python\")\n",
|
444 |
" return after.split(\"```\")[0]\n",
|
445 |
-
"file_val = None\n",
|
446 |
-
"def do_stuff(file, extra):\n",
|
447 |
-
" assert False, (file, extra)\n",
|
448 |
-
" return pd.read_csv(file.name)\n",
|
449 |
-
" file_val = file\n",
|
450 |
"\n",
|
451 |
"import io\n",
|
452 |
"def generate_code(val):\n",
|
@@ -471,14 +458,22 @@
|
|
471 |
"def generate_step_markdown(step_number: int, subtitle: str):\n",
|
472 |
" return gr.Markdown(f\"# Step {step_number}\\n\\n ### {subtitle}\")\n",
|
473 |
"\n",
|
474 |
-
"
|
475 |
-
"
|
476 |
-
"
|
|
|
|
|
477 |
"\n",
|
478 |
-
"def
|
479 |
-
"
|
|
|
480 |
" f.write(val)\n",
|
481 |
-
" return gr.File.update(value
|
|
|
|
|
|
|
|
|
|
|
482 |
"\n",
|
483 |
"with gr.Blocks() as demo:\n",
|
484 |
" # STEP 1\n",
|
@@ -501,36 +496,47 @@
|
|
501 |
" table_mapping_df = gr.DataFrame(type=\"pandas\")\n",
|
502 |
" generate_mapping_btn.click(fn=get_table_mapping, inputs=[source_df, template_df], outputs=[table_mapping_df])\n",
|
503 |
" \n",
|
504 |
-
" # STEP 3\n",
|
505 |
-
" generate_step_markdown(3, \"Save mapping to CSV and download (optional).\")\n",
|
506 |
" with gr.Row():\n",
|
507 |
" save_mapping_btn = gr.Button(value=\"Save Mapping\", variant=\"secondary\")\n",
|
508 |
" with gr.Row():\n",
|
509 |
" csv = gr.File(interactive=False, visible=False)\n",
|
510 |
-
" save_mapping_btn.click(
|
511 |
" mapping_file = gr.File(label=\"Downloaded File\", visible=False)\n",
|
512 |
" mapping_file.change(lambda x: x, mapping_file, table_mapping_df)\n",
|
513 |
-
"
|
514 |
-
"
|
|
|
515 |
" with gr.Row():\n",
|
516 |
" generate_code_btn = gr.Button(value=\"Generate Code from Mapping\", variant=\"primary\")\n",
|
517 |
" with gr.Row():\n",
|
518 |
" code_block = gr.Code(language=\"python\")\n",
|
519 |
" generate_code_btn.click(fn=generate_code, outputs=[code_block])\n",
|
520 |
"\n",
|
521 |
-
" # STEP 5\n",
|
522 |
-
" generate_step_markdown(5, \"Save transformation code (optional).\")\n",
|
523 |
" with gr.Row():\n",
|
524 |
" save_code_btn = gr.Button(value=\"Save Code\", variant=\"secondary\")\n",
|
525 |
" with gr.Row():\n",
|
526 |
" text = gr.File(interactive=False, visible=False)\n",
|
527 |
-
" save_code_btn.click(
|
528 |
" code_file = gr.File(label=\"Downloaded File\", visible=False)\n",
|
529 |
" code_file.change(lambda x: x, code_file, code_block)\n",
|
530 |
"\n",
|
531 |
-
" #
|
532 |
-
"
|
533 |
-
"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
534 |
" \n",
|
535 |
" # with gr.Row():\n",
|
536 |
" # with gr.Column():\n",
|
@@ -596,67 +602,6 @@
|
|
596 |
"demo.launch()"
|
597 |
]
|
598 |
},
|
599 |
-
{
|
600 |
-
"cell_type": "code",
|
601 |
-
"execution_count": 22,
|
602 |
-
"metadata": {},
|
603 |
-
"outputs": [
|
604 |
-
{
|
605 |
-
"name": "stdout",
|
606 |
-
"output_type": "stream",
|
607 |
-
"text": [
|
608 |
-
"Running on local URL: http://127.0.0.1:7866\n",
|
609 |
-
"\n",
|
610 |
-
"To create a public link, set `share=True` in `launch()`.\n"
|
611 |
-
]
|
612 |
-
},
|
613 |
-
{
|
614 |
-
"data": {
|
615 |
-
"text/html": [
|
616 |
-
"<div><iframe src=\"http://127.0.0.1:7866/\" width=\"100%\" height=\"500\" allow=\"autoplay; camera; microphone; clipboard-read; clipboard-write;\" frameborder=\"0\" allowfullscreen></iframe></div>"
|
617 |
-
],
|
618 |
-
"text/plain": [
|
619 |
-
"<IPython.core.display.HTML object>"
|
620 |
-
]
|
621 |
-
},
|
622 |
-
"metadata": {},
|
623 |
-
"output_type": "display_data"
|
624 |
-
},
|
625 |
-
{
|
626 |
-
"data": {
|
627 |
-
"text/plain": []
|
628 |
-
},
|
629 |
-
"execution_count": 22,
|
630 |
-
"metadata": {},
|
631 |
-
"output_type": "execute_result"
|
632 |
-
}
|
633 |
-
],
|
634 |
-
"source": [
|
635 |
-
"import gradio as gr\n",
|
636 |
-
"\n",
|
637 |
-
"def mock_ocr(f):\n",
|
638 |
-
" return [[1, 2, 3], [4, 5, 6]]\n",
|
639 |
-
"\n",
|
640 |
-
"def export_csv(d):\n",
|
641 |
-
" d.to_csv(\"output.csv\")\n",
|
642 |
-
" return gr.File.update(value=\"output.csv\", visible=True)\n",
|
643 |
-
"\n",
|
644 |
-
"with gr.Blocks() as demo:\n",
|
645 |
-
" with gr.Row():\n",
|
646 |
-
" file = gr.File(label=\"PDF file\", file_types=[\".pdf\"])\n",
|
647 |
-
" dataframe = gr.Dataframe()\n",
|
648 |
-
" \n",
|
649 |
-
" with gr.Column():\n",
|
650 |
-
" button = gr.Button(\"Export\")\n",
|
651 |
-
" csv = gr.File(interactive=False, visible=False)\n",
|
652 |
-
" \n",
|
653 |
-
" \n",
|
654 |
-
" file.change(mock_ocr, file, dataframe)\n",
|
655 |
-
" button.click(export_csv, dataframe, csv)\n",
|
656 |
-
" \n",
|
657 |
-
"demo.launch()"
|
658 |
-
]
|
659 |
-
},
|
660 |
{
|
661 |
"cell_type": "code",
|
662 |
"execution_count": 176,
|
|
|
383 |
},
|
384 |
{
|
385 |
"cell_type": "code",
|
386 |
+
"execution_count": 43,
|
387 |
"metadata": {},
|
388 |
"outputs": [
|
389 |
{
|
390 |
"name": "stderr",
|
391 |
"output_type": "stream",
|
392 |
"text": [
|
393 |
+
"/var/folders/lx/3ksh07r96gn2v7b8mb__3mpc0000gn/T/ipykernel_13584/3295794268.py:55: GradioUnusedKwargWarning: You have unused kwarg parameters in UploadButton, please remove them: {'live': True}\n",
|
394 |
" upload_template_btn = gr.UploadButton(label=\"Upload Template File\", file_types = ['.csv'], live=True, file_count = \"single\")\n",
|
395 |
+
"/var/folders/lx/3ksh07r96gn2v7b8mb__3mpc0000gn/T/ipykernel_13584/3295794268.py:59: GradioUnusedKwargWarning: You have unused kwarg parameters in UploadButton, please remove them: {'live': True}\n",
|
396 |
" upload_source_button = gr.UploadButton(label=\"Upload Source File\", file_types = ['.csv'], live=True, file_count = \"single\")\n",
|
397 |
+
"/Users/andybryant/Desktop/projects/zero-mapper/venv/lib/python3.9/site-packages/gradio/utils.py:841: UserWarning: Expected 1 arguments for function <function generate_code at 0x12c23b820>, received 0.\n",
|
398 |
" warnings.warn(\n",
|
399 |
+
"/Users/andybryant/Desktop/projects/zero-mapper/venv/lib/python3.9/site-packages/gradio/utils.py:845: UserWarning: Expected at least 1 arguments for function <function generate_code at 0x12c23b820>, received 0.\n",
|
400 |
" warnings.warn(\n"
|
401 |
]
|
402 |
},
|
|
|
404 |
"name": "stdout",
|
405 |
"output_type": "stream",
|
406 |
"text": [
|
407 |
+
"Running on local URL: http://127.0.0.1:7883\n",
|
408 |
"\n",
|
409 |
"To create a public link, set `share=True` in `launch()`.\n"
|
410 |
]
|
|
|
412 |
{
|
413 |
"data": {
|
414 |
"text/html": [
|
415 |
+
"<div><iframe src=\"http://127.0.0.1:7883/\" width=\"100%\" height=\"500\" allow=\"autoplay; camera; microphone; clipboard-read; clipboard-write;\" frameborder=\"0\" allowfullscreen></iframe></div>"
|
416 |
],
|
417 |
"text/plain": [
|
418 |
"<IPython.core.display.HTML object>"
|
|
|
425 |
"data": {
|
426 |
"text/plain": []
|
427 |
},
|
428 |
+
"execution_count": 43,
|
429 |
"metadata": {},
|
430 |
"output_type": "execute_result"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
431 |
}
|
432 |
],
|
433 |
"source": [
|
434 |
"def _sanitize_python_output(text: str):\n",
|
435 |
" _, after = text.split(\"```python\")\n",
|
436 |
" return after.split(\"```\")[0]\n",
|
|
|
|
|
|
|
|
|
|
|
437 |
"\n",
|
438 |
"import io\n",
|
439 |
"def generate_code(val):\n",
|
|
|
458 |
"def generate_step_markdown(step_number: int, subtitle: str):\n",
|
459 |
" return gr.Markdown(f\"# Step {step_number}\\n\\n ### {subtitle}\")\n",
|
460 |
"\n",
|
461 |
+
"# TODO: parameterize\n",
|
462 |
+
"def export_table_mapping(d):\n",
|
463 |
+
" filename = \"source_template_mapping.csv\"\n",
|
464 |
+
" d.to_csv(filename)\n",
|
465 |
+
" return gr.File.update(value=filename, visible=True)\n",
|
466 |
"\n",
|
467 |
+
"def export_python_code(val):\n",
|
468 |
+
" filename = \"transformation_code.py\"\n",
|
469 |
+
" with open(filename, \"w\") as f:\n",
|
470 |
" f.write(val)\n",
|
471 |
+
" return gr.File.update(value=filename, visible=True)\n",
|
472 |
+
"\n",
|
473 |
+
"def export_transformed_source(d):\n",
|
474 |
+
" filename = \"transformed_source.csv\"\n",
|
475 |
+
" d.to_csv(filename)\n",
|
476 |
+
" return gr.File.update(value=filename, visible=True)\n",
|
477 |
"\n",
|
478 |
"with gr.Blocks() as demo:\n",
|
479 |
" # STEP 1\n",
|
|
|
496 |
" table_mapping_df = gr.DataFrame(type=\"pandas\")\n",
|
497 |
" generate_mapping_btn.click(fn=get_table_mapping, inputs=[source_df, template_df], outputs=[table_mapping_df])\n",
|
498 |
" \n",
|
|
|
|
|
499 |
" with gr.Row():\n",
|
500 |
" save_mapping_btn = gr.Button(value=\"Save Mapping\", variant=\"secondary\")\n",
|
501 |
" with gr.Row():\n",
|
502 |
" csv = gr.File(interactive=False, visible=False)\n",
|
503 |
+
" save_mapping_btn.click(export_table_mapping, table_mapping_df, csv)\n",
|
504 |
" mapping_file = gr.File(label=\"Downloaded File\", visible=False)\n",
|
505 |
" mapping_file.change(lambda x: x, mapping_file, table_mapping_df)\n",
|
506 |
+
" \n",
|
507 |
+
" # STEP 3\n",
|
508 |
+
" generate_step_markdown(3, \"Generate python code to transform Source to Template, using the generated mapping.\")\n",
|
509 |
" with gr.Row():\n",
|
510 |
" generate_code_btn = gr.Button(value=\"Generate Code from Mapping\", variant=\"primary\")\n",
|
511 |
" with gr.Row():\n",
|
512 |
" code_block = gr.Code(language=\"python\")\n",
|
513 |
" generate_code_btn.click(fn=generate_code, outputs=[code_block])\n",
|
514 |
"\n",
|
|
|
|
|
515 |
" with gr.Row():\n",
|
516 |
" save_code_btn = gr.Button(value=\"Save Code\", variant=\"secondary\")\n",
|
517 |
" with gr.Row():\n",
|
518 |
" text = gr.File(interactive=False, visible=False)\n",
|
519 |
+
" save_code_btn.click(export_python_code, code_block, text)\n",
|
520 |
" code_file = gr.File(label=\"Downloaded File\", visible=False)\n",
|
521 |
" code_file.change(lambda x: x, code_file, code_block)\n",
|
522 |
"\n",
|
523 |
+
" # STEP 4\n",
|
524 |
+
" generate_step_markdown(4, \"Transform the Source CSV into the Template CSV using the generated code.\")\n",
|
525 |
+
" with gr.Row():\n",
|
526 |
+
" transform_btn = gr.Button(value=\"Transform Source\", variant=\"primary\")\n",
|
527 |
+
" with gr.Row():\n",
|
528 |
+
" source_df_transformed = gr.Dataframe(type=\"pandas\")\n",
|
529 |
+
" transform_btn.click(lambda x: x, inputs=[source_df], outputs=[source_df_transformed])\n",
|
530 |
+
"\n",
|
531 |
+
" with gr.Row():\n",
|
532 |
+
" save_transformed_source_btn = gr.Button(value=\"Save Transformed Source\", variant=\"secondary\")\n",
|
533 |
+
" with gr.Row():\n",
|
534 |
+
" csv = gr.File(interactive=False, visible=False)\n",
|
535 |
+
" save_transformed_source_btn.click(export_transformed_source, source_df_transformed, csv)\n",
|
536 |
+
" transform_file = gr.File(label=\"Downloaded File\", visible=False)\n",
|
537 |
+
" transform_file.change(lambda x: x, transform_file, source_df_transformed)\n",
|
538 |
+
"\n",
|
539 |
+
" \n",
|
540 |
" \n",
|
541 |
" # with gr.Row():\n",
|
542 |
" # with gr.Column():\n",
|
|
|
602 |
"demo.launch()"
|
603 |
]
|
604 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
605 |
{
|
606 |
"cell_type": "code",
|
607 |
"execution_count": 176,
|