nomadicsynth commited on
Commit
76f92f8
·
1 Parent(s): c138584

Refactor UI layout in create_interface function to use tabs for better organization and accessibility of content

Browse files
Files changed (1) hide show
  1. app.py +233 -228
app.py CHANGED
@@ -551,253 +551,258 @@ def create_interface():
551
  display: none;
552
  }"""
553
  ) as demo:
554
- gr.HTML(
555
- """
556
- <div style="text-align: center; margin-bottom: 1rem">
557
- <h1>Inkling</h1>
558
- <p>Discover papers with deep conceptual connections to your research</p>
559
- <p>An experiment in AI-assisted research discovery and insight generation</p>
560
- </div>
561
- """
562
- )
563
-
564
- with gr.Accordion(label="Instructions and Privacy Policy", open=False):
565
- gr.Markdown(
566
  """
567
- This tool helps you uncover research papers with **deep, meaningful connections** to your ideas.
568
- It uses AI to go beyond keyword or semantic similarity — analyzing how papers relate **conceptually** and **contextually**,
569
- even when the surface topics differ.
570
-
571
- The focus is on surfacing *novel insights* — connections that may not be obvious at a glance,
572
- but could **spark new perspectives**, **deepen understanding**, or **highlight relationships that might otherwise be overlooked**.
573
 
574
- It’s designed to act more like a research collaborator than a search engine — helping you explore conceptual bridges and
575
- unexpected pathways in the literature.
 
 
 
 
576
 
577
- Please ask any questions or provide feedback on the tool to help us improve it by starting a discussion on
578
- the [Community Tab](https://huggingface.co/spaces/nomadicsynth/inkling/discussions).
579
 
580
- **Privacy Policy**: Each query and the results returned will be logged for research and development purposes.
581
- Additionally, the abstract or research description you provide will be included in any feedback
582
- you submit and may be used to improve the model, and published in a public dataset.
583
- Please ensure that you have the right to share this information.
584
- By submitting a query and/or feedback, you agree to the use of this information for research purposes.
585
- Do not include personally identifiable, proprietary, or sensitive information.
586
- """
587
- )
588
- gr.Markdown(
589
- """
590
- 1. **Enter Abstract**: Paste an abstract or describe your research question or idea in the text box.
591
- 2. **Find Related Papers**: Click the button to explore conceptually related research.
592
- 3. **Select a Paper**: Click on a row in the results table to view more details.
593
- 4. **Analyze Connection**: Click the analysis button to explore the potential connection between the papers.
594
- 5. **Insight Analysis**: Review the model’s reasoning about how and why these papers may relate meaningfully.
595
- """
596
- )
597
 
598
- abstract_input = gr.Textbox(
599
- label="Paper Abstract or Description",
600
- placeholder="Paste an abstract or describe research details...",
601
- lines=8,
602
- key="abstract",
603
- )
604
- search_btn = gr.Button("Find Related Papers", variant="primary")
605
-
606
- # Store full paper data
607
- paper_data_state = gr.State([])
608
-
609
- # Store query abstract
610
- query_abstract_state = gr.State("")
611
-
612
- # Store selected paper
613
- selected_paper_state = gr.State(None)
614
-
615
- # Use Dataframe for results
616
- results_df = gr.Dataframe(
617
- headers=["Title", "Authors", "Categories", "Date", "Match Score"],
618
- datatype=["markdown", "markdown", "str", "date", "str"],
619
- latex_delimiters=latex_delimiters,
620
- label="Related Papers",
621
- interactive=False,
622
- wrap=False,
623
- line_breaks=False,
624
- column_widths=["40%", "20%", "20%", "10%", "10%", "0%"], # Hide ID column
625
- key="results",
626
- )
627
 
628
- with gr.Row():
629
- with gr.Column(scale=1):
630
- paper_details_output = gr.Markdown(
631
- value="# Paper Details",
632
- label="Paper Details",
633
- latex_delimiters=latex_delimiters,
634
- show_copy_button=True,
635
- key="paper_details",
636
- )
637
- analyze_btn = gr.Button("Analyze Connection", variant="primary", visible=False)
638
- with gr.Accordion(label="Feedback and Flagging", open=True, visible=False) as paper_feedback_accordion:
639
- gr.Markdown(
640
- """
641
- Please provide feedback on the relevance of this paper to your input.
642
- This helps us improve how well the system identifies meaningful research connections.
643
  """
644
  )
645
- paper_feedback = gr.Radio(
646
- ["👍 Good Match", "👎 Poor Match"],
647
- label="Is this paper meaningfully related to your query?",
648
- )
649
- paper_expert = gr.Checkbox(label="I am an expert in this field", value=False)
650
- paper_comment = gr.Textbox(label="Additional feedback on this match (optional)")
651
- flag_paper_btn = gr.Button("Submit Paper Feedback")
652
-
653
- with gr.Column(scale=1):
654
- analysis_output = gr.Markdown(
655
- value="# Connection Analysis",
656
- label="Connection Analysis",
657
- latex_delimiters=latex_delimiters,
658
- show_copy_button=True,
659
- key="analysis_output",
660
- )
661
- with gr.Accordion(
662
- label="Feedback and Flagging", open=True, visible=False
663
- ) as analysis_feedback_accordion:
664
  gr.Markdown(
665
  """
666
- This connection analysis was generated by an AI model trained to reason about conceptual links between research papers.
667
- If you find the explanation helpful, unclear, or off-base, your feedback will help refine the model’s reasoning process.
 
 
 
668
  """
669
  )
670
- analysis_feedback = gr.Radio(
671
- ["👍 Helpful", "👎 Not Helpful"],
672
- label="Was this explanation useful in understanding the connection?",
673
- )
674
- analysis_expert = gr.Checkbox(label="I am an expert in this field", value=False)
675
- analysis_comment = gr.Textbox(label="Additional feedback on the analysis (optional)")
676
- flag_analysis_btn = gr.Button("Submit Analysis Feedback")
677
-
678
- # Hidden UI elements for API endpoint
679
- abstract_input_hidden = gr.Textbox(visible=False, label="Abstract Input", key="abstract_hidden")
680
- synergistic_papers_output = gr.Textbox(
681
- visible=False, label="Synergistic Papers", key="synergistic_papers_output"
682
- )
683
- search_btn_hidden = gr.Button(visible=False, key="search_hidden")
684
-
685
- # API endpoint for find_synergistic_papers
686
- search_btn_hidden.click(
687
- format_search_results_json,
688
- inputs=[abstract_input_hidden],
689
- outputs=[synergistic_papers_output],
690
- api_name="find_synergistic_papers",
691
- )
692
 
693
- # Set up logging directories
694
- flagged_paper_matches_path = data_path + "/flagged_paper_matches"
695
- flagged_analyses_path = data_path + "/flagged_analyses"
696
- os.makedirs(flagged_paper_matches_path, exist_ok=True)
697
- os.makedirs(flagged_analyses_path, exist_ok=True)
 
 
698
 
699
- # Set up loggers
700
- paper_match_logger.setup(
701
- [abstract_input, paper_details_output, paper_feedback, paper_expert, paper_comment],
702
- flagged_paper_matches_path,
703
- )
704
- analysis_logger.setup(
705
- [
706
- abstract_input,
707
- paper_details_output,
708
- analysis_output,
709
- analysis_feedback,
710
- analysis_expert,
711
- analysis_comment,
712
- ],
713
- flagged_analyses_path,
714
- )
715
 
716
- # Display paper details when row is selected
717
- def on_select(evt: gr.SelectData, papers, query):
718
- selected_index = evt.index[0] # Get the row index
719
- selected = papers[selected_index]
720
-
721
- # Format paper details
722
- details_md = format_paper_as_markdown(selected)
723
-
724
- return details_md, selected
725
-
726
- # Connect search button to the search function
727
- search_btn.click(
728
- format_search_results,
729
- inputs=[abstract_input],
730
- outputs=[results_df, paper_data_state],
731
- api_name="search",
732
- ).then(
733
- lambda x: x, # Identity function to pass through the abstract
734
- inputs=[abstract_input],
735
- outputs=[query_abstract_state],
736
- api_name=False,
737
- ).then(
738
- lambda: None, # Reset selected paper
739
- outputs=[selected_paper_state],
740
- api_name=False,
741
- ).then(
742
- lambda: (
743
- gr.update(visible=False),
744
- gr.update(visible=False),
745
- gr.update(visible=False),
746
- ), # Hide analyze button and feedback accordions
747
- outputs=[analyze_btn, paper_feedback_accordion, analysis_feedback_accordion],
748
- api_name=False,
749
- ).then(
750
- lambda: ("# Paper Details", "# Synergy Analysis"), # Clear previous outputs
751
- outputs=[paper_details_output, analysis_output],
752
- api_name=False,
753
- )
754
 
755
- # Use built-in select event from Dataframe
756
- results_df.select(
757
- on_select,
758
- inputs=[paper_data_state, query_abstract_state],
759
- outputs=[paper_details_output, selected_paper_state],
760
- api_name=False,
761
- ).then(
762
- lambda: (gr.update(visible=True), gr.update(visible=True)), # Show analyze button and feedback accordion
763
- outputs=[analyze_btn, paper_feedback_accordion],
764
- api_name=False,
765
- )
766
 
767
- # Connect analyze button to run analysis
768
- analyze_btn.click(
769
- analyse_abstracts,
770
- inputs=[query_abstract_state, selected_paper_state],
771
- outputs=[analysis_output],
772
- show_progress_on=[paper_details_output, analysis_output],
773
- api_name=False,
774
- ).then(
775
- lambda: gr.update(visible=True), # Show feedback accordion
776
- outputs=[analysis_feedback_accordion],
777
- api_name=False,
778
- )
779
 
780
- # Add flagging handlers
781
- flag_paper_btn.click(
782
- lambda *args: paper_match_logger.flag(list(args)),
783
- inputs=[abstract_input, paper_details_output, paper_feedback, paper_expert, paper_comment],
784
- preprocess=False,
785
- api_name=False,
786
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
787
 
788
- flag_analysis_btn.click(
789
- lambda *args: analysis_logger.flag(list(args)),
790
- inputs=[
791
- abstract_input,
792
- paper_details_output,
793
- analysis_output,
794
- analysis_feedback,
795
- analysis_expert,
796
- analysis_comment,
797
- ],
798
- preprocess=False,
799
- api_name=False,
800
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
801
 
802
  return demo
803
 
 
551
  display: none;
552
  }"""
553
  ) as demo:
554
+ with gr.Tabs():
555
+ with gr.Tab("Home"):
556
+ gr.HTML(
557
+ """
558
+ <div style="text-align: center; margin-bottom: 1rem">
559
+ <h1>Inkling</h1>
560
+ <p>Discover papers with deep conceptual connections to your research</p>
561
+ <p>An experiment in AI-assisted research discovery and insight generation</p>
562
+ </div>
 
 
 
563
  """
564
+ )
 
 
 
 
 
565
 
566
+ with gr.Accordion(label="Instructions and Privacy Policy", open=False):
567
+ gr.Markdown(
568
+ """
569
+ This tool helps you uncover research papers with **deep, meaningful connections** to your ideas.
570
+ It uses AI to go beyond keyword or semantic similarity — analyzing how papers relate **conceptually** and **contextually**,
571
+ even when the surface topics differ.
572
 
573
+ The focus is on surfacing *novel insights* connections that may not be obvious at a glance,
574
+ but could **spark new perspectives**, **deepen understanding**, or **highlight relationships that might otherwise be overlooked**.
575
 
576
+ It’s designed to act more like a research collaborator than a search engine — helping you explore conceptual bridges and
577
+ unexpected pathways in the literature.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
578
 
579
+ Please ask any questions or provide feedback on the tool to help us improve it by starting a discussion on
580
+ the [Community Tab](https://huggingface.co/spaces/nomadicsynth/inkling/discussions).
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
581
 
582
+ **Privacy Policy**: Each query and the results returned will be logged for research and development purposes.
583
+ Additionally, the abstract or research description you provide will be included in any feedback
584
+ you submit and may be used to improve the model, and published in a public dataset.
585
+ Please ensure that you have the right to share this information.
586
+ By submitting a query and/or feedback, you agree to the use of this information for research purposes.
587
+ Do not include personally identifiable, proprietary, or sensitive information.
 
 
 
 
 
 
 
 
 
588
  """
589
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
590
  gr.Markdown(
591
  """
592
+ 1. **Enter Abstract**: Paste an abstract or describe your research question or idea in the text box.
593
+ 2. **Find Related Papers**: Click the button to explore conceptually related research.
594
+ 3. **Select a Paper**: Click on a row in the results table to view more details.
595
+ 4. **Analyze Connection**: Click the analysis button to explore the potential connection between the papers.
596
+ 5. **Insight Analysis**: Review the model’s reasoning about how and why these papers may relate meaningfully.
597
  """
598
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
599
 
600
+ abstract_input = gr.Textbox(
601
+ label="Paper Abstract or Description",
602
+ placeholder="Paste an abstract or describe research details...",
603
+ lines=8,
604
+ key="abstract",
605
+ )
606
+ search_btn = gr.Button("Find Related Papers", variant="primary")
607
 
608
+ # Store full paper data
609
+ paper_data_state = gr.State([])
 
 
 
 
 
 
 
 
 
 
 
 
 
 
610
 
611
+ # Store query abstract
612
+ query_abstract_state = gr.State("")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
613
 
614
+ # Store selected paper
615
+ selected_paper_state = gr.State(None)
 
 
 
 
 
 
 
 
 
616
 
617
+ # Use Dataframe for results
618
+ results_df = gr.Dataframe(
619
+ headers=["Title", "Authors", "Categories", "Date", "Match Score"],
620
+ datatype=["markdown", "markdown", "str", "date", "str"],
621
+ latex_delimiters=latex_delimiters,
622
+ label="Related Papers",
623
+ interactive=False,
624
+ wrap=False,
625
+ line_breaks=False,
626
+ column_widths=["40%", "20%", "20%", "10%", "10%", "0%"], # Hide ID column
627
+ key="results",
628
+ )
629
 
630
+ with gr.Row():
631
+ with gr.Column(scale=1):
632
+ paper_details_output = gr.Markdown(
633
+ value="# Paper Details",
634
+ label="Paper Details",
635
+ latex_delimiters=latex_delimiters,
636
+ show_copy_button=True,
637
+ key="paper_details",
638
+ )
639
+ analyze_btn = gr.Button("Analyze Connection", variant="primary", visible=False)
640
+ with gr.Accordion(label="Feedback and Flagging", open=True, visible=False) as paper_feedback_accordion:
641
+ gr.Markdown(
642
+ """
643
+ Please provide feedback on the relevance of this paper to your input.
644
+ This helps us improve how well the system identifies meaningful research connections.
645
+ """
646
+ )
647
+ paper_feedback = gr.Radio(
648
+ ["👍 Good Match", "👎 Poor Match"],
649
+ label="Is this paper meaningfully related to your query?",
650
+ )
651
+ paper_expert = gr.Checkbox(label="I am an expert in this field", value=False)
652
+ paper_comment = gr.Textbox(label="Additional feedback on this match (optional)")
653
+ flag_paper_btn = gr.Button("Submit Paper Feedback")
654
+
655
+ with gr.Column(scale=1):
656
+ analysis_output = gr.Markdown(
657
+ value="# Connection Analysis",
658
+ label="Connection Analysis",
659
+ latex_delimiters=latex_delimiters,
660
+ show_copy_button=True,
661
+ key="analysis_output",
662
+ )
663
+ with gr.Accordion(
664
+ label="Feedback and Flagging", open=True, visible=False
665
+ ) as analysis_feedback_accordion:
666
+ gr.Markdown(
667
+ """
668
+ This connection analysis was generated by an AI model trained to reason about conceptual links between research papers.
669
+ If you find the explanation helpful, unclear, or off-base, your feedback will help refine the model’s reasoning process.
670
+ """
671
+ )
672
+ analysis_feedback = gr.Radio(
673
+ ["👍 Helpful", "👎 Not Helpful"],
674
+ label="Was this explanation useful in understanding the connection?",
675
+ )
676
+ analysis_expert = gr.Checkbox(label="I am an expert in this field", value=False)
677
+ analysis_comment = gr.Textbox(label="Additional feedback on the analysis (optional)")
678
+ flag_analysis_btn = gr.Button("Submit Analysis Feedback")
679
+
680
+ # Hidden UI elements for API endpoint
681
+ abstract_input_hidden = gr.Textbox(visible=False, label="Abstract Input", key="abstract_hidden")
682
+ synergistic_papers_output = gr.Textbox(
683
+ visible=False, label="Synergistic Papers", key="synergistic_papers_output"
684
+ )
685
+ search_btn_hidden = gr.Button(visible=False, key="search_hidden")
686
+
687
+ # API endpoint for find_synergistic_papers
688
+ search_btn_hidden.click(
689
+ format_search_results_json,
690
+ inputs=[abstract_input_hidden],
691
+ outputs=[synergistic_papers_output],
692
+ api_name="find_synergistic_papers",
693
+ )
694
 
695
+ # Set up logging directories
696
+ flagged_paper_matches_path = data_path + "/flagged_paper_matches"
697
+ flagged_analyses_path = data_path + "/flagged_analyses"
698
+ os.makedirs(flagged_paper_matches_path, exist_ok=True)
699
+ os.makedirs(flagged_analyses_path, exist_ok=True)
700
+
701
+ # Set up loggers
702
+ paper_match_logger.setup(
703
+ [abstract_input, paper_details_output, paper_feedback, paper_expert, paper_comment],
704
+ flagged_paper_matches_path,
705
+ )
706
+ analysis_logger.setup(
707
+ [
708
+ abstract_input,
709
+ paper_details_output,
710
+ analysis_output,
711
+ analysis_feedback,
712
+ analysis_expert,
713
+ analysis_comment,
714
+ ],
715
+ flagged_analyses_path,
716
+ )
717
+
718
+ # Display paper details when row is selected
719
+ def on_select(evt: gr.SelectData, papers, query):
720
+ selected_index = evt.index[0] # Get the row index
721
+ selected = papers[selected_index]
722
+
723
+ # Format paper details
724
+ details_md = format_paper_as_markdown(selected)
725
+
726
+ return details_md, selected
727
+
728
+ # Connect search button to the search function
729
+ search_btn.click(
730
+ format_search_results,
731
+ inputs=[abstract_input],
732
+ outputs=[results_df, paper_data_state],
733
+ api_name="search",
734
+ ).then(
735
+ lambda x: x, # Identity function to pass through the abstract
736
+ inputs=[abstract_input],
737
+ outputs=[query_abstract_state],
738
+ api_name=False,
739
+ ).then(
740
+ lambda: None, # Reset selected paper
741
+ outputs=[selected_paper_state],
742
+ api_name=False,
743
+ ).then(
744
+ lambda: (
745
+ gr.update(visible=False),
746
+ gr.update(visible=False),
747
+ gr.update(visible=False),
748
+ ), # Hide analyze button and feedback accordions
749
+ outputs=[analyze_btn, paper_feedback_accordion, analysis_feedback_accordion],
750
+ api_name=False,
751
+ ).then(
752
+ lambda: ("# Paper Details", "# Synergy Analysis"), # Clear previous outputs
753
+ outputs=[paper_details_output, analysis_output],
754
+ api_name=False,
755
+ )
756
+
757
+ # Use built-in select event from Dataframe
758
+ results_df.select(
759
+ on_select,
760
+ inputs=[paper_data_state, query_abstract_state],
761
+ outputs=[paper_details_output, selected_paper_state],
762
+ api_name=False,
763
+ ).then(
764
+ lambda: (gr.update(visible=True), gr.update(visible=True)), # Show analyze button and feedback accordion
765
+ outputs=[analyze_btn, paper_feedback_accordion],
766
+ api_name=False,
767
+ )
768
+
769
+ # Connect analyze button to run analysis
770
+ analyze_btn.click(
771
+ analyse_abstracts,
772
+ inputs=[query_abstract_state, selected_paper_state],
773
+ outputs=[analysis_output],
774
+ show_progress_on=[paper_details_output, analysis_output],
775
+ api_name=False,
776
+ ).then(
777
+ lambda: gr.update(visible=True), # Show feedback accordion
778
+ outputs=[analysis_feedback_accordion],
779
+ api_name=False,
780
+ )
781
+
782
+ # Add flagging handlers
783
+ flag_paper_btn.click(
784
+ lambda *args: paper_match_logger.flag(list(args)),
785
+ inputs=[abstract_input, paper_details_output, paper_feedback, paper_expert, paper_comment],
786
+ preprocess=False,
787
+ api_name=False,
788
+ )
789
+
790
+ flag_analysis_btn.click(
791
+ lambda *args: analysis_logger.flag(list(args)),
792
+ inputs=[
793
+ abstract_input,
794
+ paper_details_output,
795
+ analysis_output,
796
+ analysis_feedback,
797
+ analysis_expert,
798
+ analysis_comment,
799
+ ],
800
+ preprocess=False,
801
+ api_name=False,
802
+ )
803
+
804
+ with gr.Tab("About"):
805
+ gr.Markdown(value=open("README.md", "r").read(), label="About")
806
 
807
  return demo
808