File size: 9,982 Bytes
0d3e375
 
 
 
 
61f57fc
0d3e375
1a0701e
6a20cba
 
 
1a0701e
 
 
6a20cba
 
0d3e375
3b85924
0d3e375
98e235c
 
cb89c28
98e235c
 
 
 
 
7236411
 
c6a3edf
98e235c
ee6c452
98e235c
 
1a0701e
 
 
98e235c
 
 
 
 
 
1a0701e
 
 
 
 
98e235c
7236411
6a20cba
98e235c
 
7236411
 
98e235c
 
1a0701e
 
 
 
 
 
 
 
 
98e235c
1a0701e
 
 
 
 
 
98e235c
7236411
1a0701e
 
 
 
 
 
 
 
 
 
0d3e375
 
ee6c452
0d3e375
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
61f57fc
 
ee6c452
61f57fc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
146a258
 
6a20cba
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
import gradio as gr
from description import *

from reference_string_parsing import *
from controlled_summarization import *
from dataset_extraction import *

from controlled_summarization import recommended_kw
import requests

# Example Usage
# url = "https://arxiv.org/pdf/2305.14996.pdf"
# dest_folder = "./examples/"
# download_pdf(url, dest_folder)


with gr.Blocks(css="#htext span {white-space: pre-line}") as demo:
    gr.Markdown("# Gradio Demo for SciAssist")
    with gr.Tabs():

        # Controlled Summarization
        with gr.TabItem("Controlled Summarization"):

            with gr.Box():
                gr.Markdown(ctrlsum_file_md)
                with gr.Row():
                    with gr.Column():
                        ctrlsum_url = gr.Textbox(label="PDF URL", max_lines=1)
                        ctrlsum_file = gr.File(label="Input File")
                        ctrlsum_str = gr.TextArea(label="Input String", max_lines=5)
                        with gr.Column():
                            gr.Markdown("* Set the length of text used for summarization. Length 0 will exert no control over length.")
                            # ctrlsum_file_beams = gr.Number(label="Number of beams for beam search", value=1, precision=0)
                            # ctrlsum_file_sequences = gr.Number(label="Number of generated summaries", value=1, precision=0)
                            ctrlsum_file_length = gr.Radio(label="Length", value=0, choices=[0, 50, 100, 200])
                            kw = gr.Radio(visible=False)
                            ctrlsum_file_keywords = gr.Textbox(label="Keywords", max_lines=1)
                        with gr.Row():
                            ctrlsum_file_btn = gr.Button("Generate")
                    ctrlsum_file_output = gr.Textbox(
                        elem_id="htext",
                        label="Summary",
                    )
                ctrlsum_file_examples = gr.Examples(
                    examples=[["examples/H01-1042_body.txt", 50, "automatic evaluation technique", "", ""],
                              ["examples/H01-1042.pdf", 0, "automatic evaluation technique", "", ""]],
                    inputs=[ctrlsum_file, ctrlsum_file_length, ctrlsum_file_keywords, ctrlsum_str, ctrlsum_url
                            ])



        ctrlsum_file_btn.click(
            fn=ctrlsum_for_file,
            inputs=[ctrlsum_file, ctrlsum_file_length, ctrlsum_file_keywords, ctrlsum_str, ctrlsum_url],
            outputs=[ctrlsum_file_output, ctrlsum_str, ctrlsum_file]
        )
        def clear():
            return None, 0, None, None, gr.Radio(visible=False)


        def update_url(url):
            if url in recommended_kw.keys():
                keywords = recommended_kw[url]
                if keywords != None:
                    return None, None, gr.Radio(choices=keywords[:3], label="Recommended Keywords", visible=True,
                                                interactive=True)

            return None, None, gr.Radio(visible=False)


        ctrlsum_file.upload(clear, inputs=None,
                            outputs=[ctrlsum_str, ctrlsum_file_length, ctrlsum_file_keywords, ctrlsum_url, kw])
        ctrlsum_url.input(update_url, inputs=ctrlsum_url, outputs=[ctrlsum_str, ctrlsum_file, kw])

        ctrlsum_str.input(clear, inputs=None,
                          outputs=[ctrlsum_url, ctrlsum_file_length, ctrlsum_file_keywords, ctrlsum_file, kw])



        def select_kw(env: gr.SelectData):
            return env.value


        kw.select(select_kw, None, ctrlsum_file_keywords)

        # Reference String Parsing
        with gr.TabItem("Reference String Parsing"):
            gr.Markdown(rsp_title_md)
            with gr.Box():
                gr.Markdown(rsp_str_md)
                with gr.Row():
                    with gr.Column():
                        rsp_str = gr.Textbox(label="Input String")
                        with gr.Column():
                            rsp_str_dehyphen = gr.Checkbox(label="dehyphen")
                        with gr.Row():
                            rsp_str_btn = gr.Button("Parse")
                    rsp_str_output = gr.HighlightedText(
                        elem_id="htext",
                        label="The Result of Parsing",
                        combine_adjacent=True,
                        adjacent_separator=" ",
                    )
                rsp_str_examples = gr.Examples(examples=[[
                                                         "Waleed Ammar, Matthew E. Peters, Chandra Bhagavat- ula, and Russell Power. 2017. The ai2 system at semeval-2017 task 10 (scienceie): semi-supervised end-to-end entity and relation extraction. In ACL workshop (SemEval).",
                                                         True],
                                                     [
                                                         "Isabelle Augenstein, Mrinal Das, Sebastian Riedel, Lakshmi Vikraman, and Andrew D. McCallum. 2017. Semeval-2017 task 10 (scienceie): Extracting keyphrases and relations from scientific publications. In ACL workshop (SemEval).",
                                                         False]], inputs=[rsp_str, rsp_str_dehyphen])
            with gr.Box():
                gr.Markdown(rsp_file_md)
                with gr.Row():
                    with gr.Column():
                        rsp_file = gr.File(label="Input File")
                        rsp_file_dehyphen = gr.Checkbox(label="dehyphen")
                        with gr.Row():
                            rsp_file_btn = gr.Button("Parse")

                    rsp_file_output = gr.HighlightedText(
                        elem_id="htext",
                        label="The Result of Parsing",
                        combine_adjacent=True,
                        adjacent_separator=" ",
                    )
                rsp_file_examples = gr.Examples(examples=[["examples/N18-3011_ref.txt", False],["examples/BERT_paper.pdf", True]], inputs=[rsp_file, rsp_file_dehyphen])


        rsp_file_btn.click(
            fn=rsp_for_file,
            inputs=[rsp_file, rsp_file_dehyphen],
            outputs=rsp_file_output
        )
        rsp_str_btn.click(
            fn=rsp_for_str,
            inputs=[rsp_str, rsp_str_dehyphen],
            outputs=rsp_str_output
        )


        # Dataset Extraction
        with gr.TabItem("Dataset Mentions Extraction"):
            gr.Markdown(de_title_md)
            with gr.Box():
                gr.Markdown(de_str_md)
                with gr.Row():
                    with gr.Column():
                        de_str = gr.Textbox(label="Input String")
                        with gr.Row():
                            de_str_btn = gr.Button("Extract")
                    de_str_output = gr.HighlightedText(
                        elem_id="htext",
                        label="The Result of Extraction",
                        combine_adjacent=True,
                        adjacent_separator=" ",
                    )
                de_str_examples = gr.Examples(examples=[["The impact of gender identity on emotions was examined by researchers using a subsample from the National Longitudinal Study of Adolescent Health. The study aimed to investigate the direct effects of gender identity on emotional experiences and expression. By focusing on a subsample of the larger study, the researchers were able to hone in on the specific relationship between gender identity and emotions. Through their analysis, the researchers sought to determine whether gender identity could have a significant and direct impact on emotional well-being. The findings of the study have important implications for our understanding of the complex interplay between gender identity and emotional experiences, and may help to inform future interventions and support for individuals who experience gender-related emotional distress."],
                                                        ["The possibility of genotype-environment interaction for memory performance and change was examined in 150 monozygotic twin pairs from the Swedish Adoption Twin Study of Aging and the National Comorbidity Survey. They aimed to explore how genetic and environmental factors could interact to affect cognitive performance in aging individuals. Through their analysis, the researchers hoped to gain a better understanding of the complex interplay between nature and nurture in determining cognitive outcomes. By investigating the unique characteristics of monozygotic twins, who share identical genetic material, the study was able to isolate the role of environmental factors in shaping cognitive abilities over time. The findings from this research have important implications for our understanding of the complex interplay between genetics and the environment in shaping cognitive outcomes in aging individuals."]],
                                                         inputs=[de_str])
            with gr.Box():
                gr.Markdown(de_file_md)
                with gr.Row():
                    with gr.Column():
                        de_file = gr.File(label="Input File")
                        with gr.Row():
                            de_file_btn = gr.Button("Extract")

                    de_file_output = gr.HighlightedText(
                        elem_id="htext",
                        label="The Result of Extraction",
                        combine_adjacent=True,
                        adjacent_separator=" ",
                    )
                de_file_examples = gr.Examples(examples=[["examples/127.txt"]], inputs=[de_file])


        de_file_btn.click(
            fn=de_for_file,
            inputs=[de_file],
            outputs=de_file_output
        )
        de_str_btn.click(
            fn=de_for_str,
            inputs=[de_str],
            outputs=de_str_output
        )


demo.launch(share=False)