chansung commited on
Commit
ca3e112
β€’
1 Parent(s): de196a0

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +214 -0
app.py ADDED
@@ -0,0 +1,214 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import copy
3
+ import datasets
4
+
5
+ STYLE = """
6
+ .small-font{
7
+ font-size: 12pt !important;
8
+ }
9
+
10
+ .small-font:hover {
11
+ font-size: 20px !important;
12
+ transition: font-size 0.3s ease-out;
13
+ transition-delay: 0.8s;
14
+ }
15
+
16
+ .group {
17
+ padding-left: 10px;
18
+ padding-right: 10px;
19
+ padding-bottom: 10px;
20
+ border: 2px dashed gray;
21
+ border-radius: 20px;
22
+ box-shadow: 5px 3px 10px 1px rgba(0, 0, 0, 0.4) !important;
23
+ }
24
+
25
+ .accordion > button > span{
26
+ font-size: 12pt !important;
27
+ }
28
+
29
+ .accordion {
30
+ border-style: dashed !important;
31
+ border-left-width: 2px !important;
32
+ border-bottom-width: 2.5px !important;
33
+ border-top: none !important;
34
+ border-right: none !important;
35
+ box-shadow: none !important;
36
+ }
37
+ """
38
+
39
+ dataset_repo_id = "chansung/auto-paper-qa2"
40
+ ds = datasets.load_dataset(dataset_repo_id)
41
+
42
+ date2qna = {}
43
+ longest_qans = 0
44
+
45
+ def count_nans(row):
46
+ count = 0
47
+
48
+ for _, (k, v) in enumerate(data.items()):
49
+ if v is None:
50
+ count = count + 1
51
+
52
+ return count
53
+
54
+ for data in ds["train"]:
55
+ date = data["target_date"].strftime("%Y-%m-%d")
56
+
57
+ if date in date2qna:
58
+ papers = copy.deepcopy(date2qna[date])
59
+ for paper in papers:
60
+ if paper["title"] == data["title"]:
61
+ if count_nans(paper) > count_nans(data):
62
+ date2qna[date].remove(paper)
63
+
64
+ date2qna[date].append(data)
65
+ del papers
66
+ else:
67
+ date2qna[date] = [data]
68
+
69
+ sorted_dates = sorted(date2qna.keys())
70
+ last_date = sorted_dates[-1]
71
+ last_papers = date2qna[last_date]
72
+ selected_paper = last_papers[0]
73
+
74
+ def get_papers(date):
75
+ papers = [paper["title"] for paper in date2qna[date]]
76
+ return gr.Dropdown(
77
+ papers,
78
+ value=papers[0]
79
+ )
80
+
81
+ def set_paper(date, paper_title):
82
+ selected_paper = None
83
+ for paper in date2qna[date]:
84
+ if paper["title"] == paper_title:
85
+ selected_paper = paper
86
+ break
87
+
88
+ return (
89
+ gr.Markdown(f"# {selected_paper['title']}"), gr.Markdown(selected_paper["summary"]),
90
+
91
+ gr.Markdown(f"## πŸ™‹ {selected_paper['0_question']}"),
92
+ gr.Markdown(f"β†ͺ **(ELI5)** {selected_paper['0_answers:eli5']}"),
93
+ gr.Markdown(f"β†ͺ **(Technical)** {selected_paper['0_answers:expert']}"),
94
+ gr.Markdown(f"## πŸ™‹πŸ™‹ {selected_paper['0_additional_depth_q:follow up question']}"),
95
+ gr.Markdown(f"β†ͺ **(ELI5)** {selected_paper['0_additional_depth_q:answers:eli5']}"),
96
+ gr.Markdown(f"β†ͺ **(Technical)** {selected_paper['0_additional_depth_q:answers:expert']}"),
97
+ gr.Markdown(f"## πŸ™‹πŸ™‹ {selected_paper['0_additional_breath_q:follow up question']}"),
98
+ gr.Markdown(f"β†ͺ **(ELI5)** {selected_paper['0_additional_breath_q:answers:eli5']}"),
99
+ gr.Markdown(f"β†ͺ **(Technical)** {selected_paper['0_additional_breath_q:answers:expert']}"),
100
+
101
+ gr.Markdown(f"## πŸ™‹ {selected_paper['1_question']}"),
102
+ gr.Markdown(f"β†ͺ **(ELI5)** {selected_paper['1_answers:eli5']}"),
103
+ gr.Markdown(f"β†ͺ **(Technical)** {selected_paper['1_answers:expert']}"),
104
+ gr.Markdown(f"## πŸ™‹πŸ™‹ {selected_paper['1_additional_depth_q:follow up question']}"),
105
+ gr.Markdown(f"β†ͺ **(ELI5)** {selected_paper['1_additional_depth_q:answers:eli5']}"),
106
+ gr.Markdown(f"β†ͺ **(Technical)** {selected_paper['1_additional_depth_q:answers:expert']}"),
107
+ gr.Markdown(f"## πŸ™‹πŸ™‹ {selected_paper['1_additional_breath_q:follow up question']}"),
108
+ gr.Markdown(f"β†ͺ **(ELI5)** {selected_paper['1_additional_breath_q:answers:eli5']}"),
109
+ gr.Markdown(f"β†ͺ **(Technical)** {selected_paper['1_additional_breath_q:answers:expert']}"),
110
+
111
+ gr.Markdown(f"## πŸ™‹ {selected_paper['2_question']}"),
112
+ gr.Markdown(f"β†ͺ **(ELI5)** {selected_paper['2_answers:eli5']}"),
113
+ gr.Markdown(f"β†ͺ **(Technical)** {selected_paper['2_answers:expert']}"),
114
+ gr.Markdown(f"## πŸ™‹πŸ™‹ {selected_paper['2_additional_depth_q:follow up question']}"),
115
+ gr.Markdown(f"β†ͺ **(ELI5)** {selected_paper['2_additional_depth_q:answers:eli5']}"),
116
+ gr.Markdown(f"β†ͺ **(Technical)** {selected_paper['2_additional_depth_q:answers:expert']}"),
117
+ gr.Markdown(f"## πŸ™‹πŸ™‹ {selected_paper['2_additional_breath_q:follow up question']}"),
118
+ gr.Markdown(f"β†ͺ **(ELI5)** {selected_paper['2_additional_breath_q:answers:eli5']}"),
119
+ gr.Markdown(f"β†ͺ **(Technical)** {selected_paper['2_additional_breath_q:answers:expert']}"),
120
+ )
121
+
122
+ with gr.Blocks(css=STYLE) as demo:
123
+ date_dd = gr.Dropdown(
124
+ sorted_dates,
125
+ value=last_date,
126
+ label="Select date",
127
+ interactive=True
128
+ )
129
+ papers_dd = gr.Dropdown(
130
+ [paper["title"] for paper in last_papers],
131
+ value=selected_paper["title"],
132
+ label="Select paper title",
133
+ interactive=True
134
+ )
135
+
136
+ date_dd.input(
137
+ get_papers,
138
+ date_dd,
139
+ papers_dd
140
+ )
141
+
142
+ title = gr.Markdown(f"# {selected_paper['title']}")
143
+ summary = gr.Markdown(f"{selected_paper['summary']}", elem_classes=["small-font"])
144
+
145
+ gr.Markdown("## Auto generated Questions & Answers")
146
+
147
+ # 1
148
+ with gr.Column(elem_classes=["group"], visible=True) as q_0:
149
+ basic_q_0 = gr.Markdown(f"## πŸ™‹ {selected_paper['0_question']}")
150
+ basic_q_eli5_0 = gr.Markdown(f"β†ͺ **(ELI5)** {selected_paper['0_answers:eli5']}", elem_classes=["small-font"])
151
+ basic_q_expert_0 = gr.Markdown(f"β†ͺ **(Technical)** {selected_paper['0_answers:expert']}", elem_classes=["small-font"])
152
+
153
+ with gr.Accordion("Additional question #1", open=False, elem_classes=["accordion"]) as aq_0_0:
154
+ depth_q_0 = gr.Markdown(f"## πŸ™‹πŸ™‹ {selected_paper['0_additional_depth_q:follow up question']}")
155
+ depth_q_eli5_0 = gr.Markdown(f"β†ͺ **(ELI5)** {selected_paper['0_additional_depth_q:answers:eli5']}", elem_classes=["small-font"])
156
+ depth_q_expert_0 = gr.Markdown(f"β†ͺ **(Technical)** {selected_paper['0_additional_depth_q:answers:expert']}", elem_classes=["small-font"])
157
+
158
+ with gr.Accordion("Additional question #2", open=False, elem_classes=["accordion"]) as aq_0_1:
159
+ breath_q_0 = gr.Markdown(f"## πŸ™‹πŸ™‹ {selected_paper['0_additional_breath_q:follow up question']}")
160
+ breath_q_eli5_0 = gr.Markdown(f"β†ͺ **(ELI5)** {selected_paper['0_additional_breath_q:answers:eli5']}", elem_classes=["small-font"])
161
+ breath_q_expert_0 = gr.Markdown(f"β†ͺ **(Technical)** {selected_paper['0_additional_breath_q:answers:expert']}", elem_classes=["small-font"])
162
+
163
+ # 2
164
+ with gr.Column(elem_classes=["group"], visible=True) as q_1:
165
+ basic_q_1 = gr.Markdown(f"## πŸ™‹ {selected_paper['1_question']}")
166
+ basic_q_eli5_1 = gr.Markdown(f"β†ͺ **(ELI5)** {selected_paper['1_answers:eli5']}", elem_classes=["small-font"])
167
+ basic_q_expert_1 = gr.Markdown(f"β†ͺ **(Technical)** {selected_paper['1_answers:expert']}", elem_classes=["small-font"])
168
+
169
+ with gr.Accordion("Additional question #1", open=False, elem_classes=["accordion"]) as aq_1_0:
170
+ depth_q_1 = gr.Markdown(f"## πŸ™‹πŸ™‹ {selected_paper['1_additional_depth_q:follow up question']}")
171
+ depth_q_eli5_1 = gr.Markdown(f"β†ͺ **(ELI5)** {selected_paper['1_additional_depth_q:answers:eli5']}", elem_classes=["small-font"])
172
+ depth_q_expert_1 = gr.Markdown(f"β†ͺ **(Technical)** {selected_paper['1_additional_depth_q:answers:expert']}", elem_classes=["small-font"])
173
+
174
+ with gr.Accordion("Additional question #2", open=False, elem_classes=["accordion"]) as aq_1_1:
175
+ breath_q_1 = gr.Markdown(f"## πŸ™‹πŸ™‹ {selected_paper['1_additional_breath_q:follow up question']}")
176
+ breath_q_eli5_1 = gr.Markdown(f"β†ͺ **(ELI5)** {selected_paper['1_additional_breath_q:answers:eli5']}", elem_classes=["small-font"])
177
+ breath_q_expert_1 = gr.Markdown(f"β†ͺ **(Technical)** {selected_paper['1_additional_breath_q:answers:expert']}", elem_classes=["small-font"])
178
+
179
+ # 3
180
+ with gr.Column(elem_classes=["group"], visible=True) as q_2:
181
+ basic_q_2 = gr.Markdown(f"## πŸ™‹ {selected_paper['2_question']}")
182
+ basic_q_eli5_2 = gr.Markdown(f"β†ͺ **(ELI5)** {selected_paper['2_answers:eli5']}", elem_classes=["small-font"])
183
+ basic_q_expert_2 = gr.Markdown(f"β†ͺ **(Technical)** {selected_paper['2_answers:expert']}", elem_classes=["small-font"])
184
+
185
+ with gr.Accordion("Additional question #1", open=False, elem_classes=["accordion"]) as aq_2_0:
186
+ depth_q_2 = gr.Markdown(f"## πŸ™‹πŸ™‹ {selected_paper['2_additional_depth_q:follow up question']}")
187
+ depth_q_eli5_2 = gr.Markdown(f"β†ͺ **(ELI5)** {selected_paper['2_additional_depth_q:answers:eli5']}", elem_classes=["small-font"])
188
+ depth_q_expert_2 = gr.Markdown(f"β†ͺ **(Technical)** {selected_paper['2_additional_depth_q:answers:expert']}", elem_classes=["small-font"])
189
+
190
+ with gr.Accordion("Additional question #2", open=False, elem_classes=["accordion"]) as aq_2_1:
191
+ breath_q_2 = gr.Markdown(f"## πŸ™‹πŸ™‹ {selected_paper['2_additional_breath_q:follow up question']}")
192
+ breath_q_eli5_2 = gr.Markdown(f"β†ͺ **(ELI5)** {selected_paper['2_additional_breath_q:answers:eli5']}", elem_classes=["small-font"])
193
+ breath_q_expert_2 = gr.Markdown(f"β†ͺ **(Technical)** {selected_paper['2_additional_breath_q:answers:expert']}", elem_classes=["small-font"])
194
+
195
+ papers_dd.input(
196
+ set_paper,
197
+ [date_dd, papers_dd],
198
+ [
199
+ title, summary,
200
+ basic_q_0, basic_q_eli5_0, basic_q_expert_0,
201
+ depth_q_0, depth_q_eli5_0, depth_q_expert_0,
202
+ breath_q_0, breath_q_eli5_0, breath_q_expert_0,
203
+
204
+ basic_q_1, basic_q_eli5_1, basic_q_expert_1,
205
+ depth_q_1, depth_q_eli5_1, depth_q_expert_1,
206
+ breath_q_1, breath_q_eli5_1, breath_q_expert_1,
207
+
208
+ basic_q_2, basic_q_eli5_2, basic_q_expert_2,
209
+ depth_q_2, depth_q_eli5_2, depth_q_expert_2,
210
+ breath_q_2, breath_q_eli5_2, breath_q_expert_2
211
+ ]
212
+ )
213
+
214
+ demo.launch(share=True)