courtneyf2 commited on
Commit
92cdc55
·
verified ·
1 Parent(s): b2b543f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +166 -4
app.py CHANGED
@@ -568,11 +568,173 @@ with gr.Blocks() as demo:
568
  outputs=[combo_output, combo_info]
569
  )
570
 
571
- # with gr.Tab("Week 5: NLP Tasks"):
572
- # # Week 5 content here
573
- # pass
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
574
 
575
-
 
 
576
 
577
  # with gr.Tab("Assignment 1"):
578
  # # Assignment content here
 
568
  outputs=[combo_output, combo_info]
569
  )
570
 
571
+ with gr.Tab("Week 5: Advanced Prompting"):
572
+ gr.Markdown("# Advanced Prompt Engineering Techniques")
573
+ gr.Markdown("Explore sophisticated prompting strategies and visualise reasoning patterns")
574
+
575
+ with gr.Tabs() as week5_tabs:
576
+
577
+ with gr.Tab("Tree of Thought Explorer"):
578
+ gr.Markdown("""
579
+ ### Visualise Multi-Path Reasoning
580
+ The model will break down your problem into multiple approaches, evaluate each one, and select the best path.
581
+ """)
582
+
583
+ with gr.Row():
584
+ tot_input = gr.Textbox(
585
+ label="Enter a problem to solve",
586
+ placeholder="e.g., How can we improve user engagement on a mobile app?",
587
+ lines=3,
588
+ value="How should a startup decide between building a mobile app or a web application first?"
589
+ )
590
+
591
+ with gr.Row():
592
+ generate_tot = gr.Button("Generate Tree of Thought", variant="primary")
593
+
594
+ with gr.Row():
595
+ tot_output = gr.Textbox(
596
+ label="Reasoning Process",
597
+ lines=12
598
+ )
599
+
600
+ with gr.Row():
601
+ tot_visualization = gr.HTML(
602
+ label="Tree Visualisation"
603
+ )
604
+
605
+ with gr.Tab("Self-Consistency Testing"):
606
+ gr.Markdown("""
607
+ ### Test Response Consistency
608
+ Run the same prompt multiple times to identify consistent patterns and areas of uncertainty.
609
+ """)
610
+
611
+ with gr.Row():
612
+ consistency_input = gr.Textbox(
613
+ label="Enter your prompt",
614
+ placeholder="Ask a question that requires reasoning...",
615
+ lines=3,
616
+ value="What are the three most important factors in choosing a database system?"
617
+ )
618
+
619
+ with gr.Row():
620
+ num_runs = gr.Slider(
621
+ minimum=3,
622
+ maximum=5,
623
+ value=3,
624
+ step=1,
625
+ label="Number of generations"
626
+ )
627
+ consistency_temp = gr.Slider(
628
+ minimum=0.3,
629
+ maximum=0.9,
630
+ value=0.7,
631
+ step=0.1,
632
+ label="Temperature"
633
+ )
634
+
635
+ with gr.Row():
636
+ generate_consistency = gr.Button("Generate Multiple Responses", variant="primary")
637
+
638
+ with gr.Row():
639
+ consistency_analysis = gr.Textbox(
640
+ label="Analysis Guide",
641
+ lines=4
642
+ )
643
+
644
+ with gr.Row():
645
+ consistency_output1 = gr.Textbox(label="Response 1", lines=5)
646
+ consistency_output2 = gr.Textbox(label="Response 2", lines=5)
647
+
648
+ with gr.Row():
649
+ consistency_output3 = gr.Textbox(label="Response 3", lines=5)
650
+ consistency_output4 = gr.Textbox(label="Response 4 (if selected)", lines=5, visible=True)
651
+
652
+ with gr.Row():
653
+ consistency_output5 = gr.Textbox(label="Response 5 (if selected)", lines=5, visible=True)
654
+
655
+ with gr.Tab("Prompt Structure Comparison"):
656
+ gr.Markdown("""
657
+ ### Compare Structural Strategies
658
+ Test how different prompt structures affect model attention and output quality.
659
+ """)
660
+
661
+ with gr.Row():
662
+ structure_input = gr.Textbox(
663
+ label="Enter your task",
664
+ placeholder="Enter a task or question...",
665
+ lines=3,
666
+ value=""
667
+ )
668
+
669
+ with gr.Row():
670
+ gr.Markdown("### Select ONE structure to test:")
671
+
672
+ with gr.Row():
673
+ structure_radio = gr.Radio(
674
+ choices=[
675
+ "Baseline (no special structure)",
676
+ "Front-loading (critical instruction first)",
677
+ "Delimiter strategy (section separation)",
678
+ "Sandwich technique (instruction at start and end)"
679
+ ],
680
+ label="Prompt Structure",
681
+ value="Baseline (no special structure)"
682
+ )
683
+
684
+ with gr.Row():
685
+ generate_structure = gr.Button("Generate Response", variant="primary")
686
+
687
+ with gr.Row():
688
+ structure_output = gr.Textbox(
689
+ label="Response",
690
+ lines=8
691
+ )
692
+ structure_info = gr.Textbox(
693
+ label="Structure Information",
694
+ lines=8
695
+ )
696
+
697
+ # Week 5 Event Handlers
698
+ def handle_tot(task):
699
+ text_output, svg_output = generate_tot_response(task)
700
+ return text_output, svg_output
701
+
702
+ def handle_consistency(prompt, runs, temp):
703
+ responses, analysis = generate_self_consistency(prompt, int(runs), temp)
704
+ while len(responses) < 5:
705
+ responses.append("")
706
+ return analysis, responses[0], responses[1], responses[2], responses[3], responses[4]
707
+
708
+ def handle_structure(task, structure_choice):
709
+ use_frontload = "Front-loading" in structure_choice
710
+ use_delimiters = "Delimiter" in structure_choice
711
+ use_sandwich = "Sandwich" in structure_choice
712
+
713
+ output, info = compare_prompt_structures(task, use_frontload, use_delimiters, use_sandwich)
714
+ return output, info
715
+
716
+ generate_tot.click(
717
+ handle_tot,
718
+ inputs=[tot_input],
719
+ outputs=[tot_output, tot_visualization]
720
+ )
721
+
722
+ generate_consistency.click(
723
+ handle_consistency,
724
+ inputs=[consistency_input, num_runs, consistency_temp],
725
+ outputs=[consistency_analysis, consistency_output1, consistency_output2,
726
+ consistency_output3, consistency_output4, consistency_output5]
727
+ )
728
+
729
+ generate_structure.click(
730
+ handle_structure,
731
+ inputs=[structure_input, structure_radio],
732
+ outputs=[structure_output, structure_info]
733
+ )
734
 
735
+ # with gr.Tab("Week 8: Error Detection"):
736
+ # # Week 8 content here
737
+ # pass
738
 
739
  # with gr.Tab("Assignment 1"):
740
  # # Assignment content here