Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
@@ -168,11 +168,13 @@ def create_embeddings(texts_to_embedd):
|
|
168 |
|
169 |
|
170 |
|
171 |
-
def predict(text_input, progress=gr.Progress()):
|
172 |
|
173 |
progress(0.1, desc="Getting queried data...")
|
174 |
# get data.
|
175 |
records_df = query_records(text_input)
|
|
|
|
|
176 |
print(records_df)
|
177 |
|
178 |
|
@@ -187,7 +189,7 @@ def predict(text_input, progress=gr.Progress()):
|
|
187 |
records_df[['x','y']] = umap_embeddings
|
188 |
|
189 |
basedata_df['color'] = '#ced4d211'
|
190 |
-
records_df['color'] = '#
|
191 |
|
192 |
progress(0.6, desc="Set up data...")
|
193 |
|
@@ -246,17 +248,17 @@ def predict(text_input, progress=gr.Progress()):
|
|
246 |
plot = datamapplot.create_interactive_plot(
|
247 |
stacked_df[['x','y']].values,
|
248 |
np.array(stacked_df['cluster_1_labels']),np.array(stacked_df['cluster_2_labels']),np.array(stacked_df['cluster_3_labels']),
|
249 |
-
hover_text=[str(
|
250 |
marker_color_array=stacked_df['color'],
|
251 |
|
252 |
use_medoids=True,
|
253 |
-
width=
|
254 |
-
height=
|
255 |
# title='The Science of <span style="color:#ab0b00;"> Consciousness </span>',
|
256 |
# sub_title=f'<div style="margin-top:20px;"> Large sample, n={len(dataset_df_filtered)}, embeddings with specter 2 & UMAP, labels: Claude 3.5 Sonnet </div>',
|
257 |
point_radius_min_pixels=1,
|
258 |
text_outline_width=5,
|
259 |
-
point_hover_color='#
|
260 |
point_radius_max_pixels=7,
|
261 |
color_label_text=False,
|
262 |
font_family="Roboto Condensed",
|
@@ -266,7 +268,7 @@ def predict(text_input, progress=gr.Progress()):
|
|
266 |
extra_point_data=extra_data,
|
267 |
on_click="window.open(`{doi}`)",
|
268 |
custom_css=custom_css,
|
269 |
-
initial_zoom_fraction=.
|
270 |
enable_search=True)
|
271 |
|
272 |
|
@@ -291,24 +293,42 @@ def predict(text_input, progress=gr.Progress()):
|
|
291 |
|
292 |
|
293 |
|
294 |
-
with gr.Blocks() as block:
|
295 |
-
|
296 |
-
##
|
297 |
-
|
298 |
-
|
299 |
-
|
300 |
-
|
301 |
-
|
302 |
-
|
303 |
-
|
304 |
-
|
305 |
-
|
306 |
-
|
|
|
|
|
|
|
307 |
|
308 |
-
new_btn.click(fn=predict, inputs=[text_input], outputs=[markdown, html])
|
309 |
|
310 |
|
|
|
|
|
|
|
311 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
312 |
|
313 |
|
314 |
|
|
|
168 |
|
169 |
|
170 |
|
171 |
+
def predict(text_input, sample_size_slider, reduce_sample_checkbox, progress=gr.Progress()):
|
172 |
|
173 |
progress(0.1, desc="Getting queried data...")
|
174 |
# get data.
|
175 |
records_df = query_records(text_input)
|
176 |
+
if reduce_sample_checkbox:
|
177 |
+
records_df = records_df.sample(sample_size_slider)
|
178 |
print(records_df)
|
179 |
|
180 |
|
|
|
189 |
records_df[['x','y']] = umap_embeddings
|
190 |
|
191 |
basedata_df['color'] = '#ced4d211'
|
192 |
+
records_df['color'] = '#f98e31'
|
193 |
|
194 |
progress(0.6, desc="Set up data...")
|
195 |
|
|
|
248 |
plot = datamapplot.create_interactive_plot(
|
249 |
stacked_df[['x','y']].values,
|
250 |
np.array(stacked_df['cluster_1_labels']),np.array(stacked_df['cluster_2_labels']),np.array(stacked_df['cluster_3_labels']),
|
251 |
+
hover_text=[str(row['title']) for ix, row in stacked_df.iterrows()],
|
252 |
marker_color_array=stacked_df['color'],
|
253 |
|
254 |
use_medoids=True,
|
255 |
+
width=1000,
|
256 |
+
height=1000,
|
257 |
# title='The Science of <span style="color:#ab0b00;"> Consciousness </span>',
|
258 |
# sub_title=f'<div style="margin-top:20px;"> Large sample, n={len(dataset_df_filtered)}, embeddings with specter 2 & UMAP, labels: Claude 3.5 Sonnet </div>',
|
259 |
point_radius_min_pixels=1,
|
260 |
text_outline_width=5,
|
261 |
+
point_hover_color='#5e2784',
|
262 |
point_radius_max_pixels=7,
|
263 |
color_label_text=False,
|
264 |
font_family="Roboto Condensed",
|
|
|
268 |
extra_point_data=extra_data,
|
269 |
on_click="window.open(`{doi}`)",
|
270 |
custom_css=custom_css,
|
271 |
+
initial_zoom_fraction=.8,
|
272 |
enable_search=True)
|
273 |
|
274 |
|
|
|
293 |
|
294 |
|
295 |
|
296 |
+
# with gr.Blocks() as block:
|
297 |
+
# gr.Markdown("""
|
298 |
+
# ## Mapping OpenAlex-Queries
|
299 |
+
|
300 |
+
# This is a tool to further interdisciplinary research – you are a neuroscientist who has used ..., What have the ... been doing with them.
|
301 |
+
# Your a philosopher of science who wonders where the concept of a fitnesslandscape has appeared...
|
302 |
+
# """)
|
303 |
+
# with gr.Row():
|
304 |
+
# with gr.Column():
|
305 |
+
# text_input = gr.Textbox(label="Name")
|
306 |
+
# markdown = gr.Markdown(label="Output Box")
|
307 |
+
# new_btn = gr.Button("New")
|
308 |
+
# with gr.Column():
|
309 |
+
# html = gr.HTML(label="HTML preview", show_label=True)
|
310 |
+
|
311 |
+
# new_btn.click(fn=predict, inputs=[text_input], outputs=[markdown, html])
|
312 |
|
|
|
313 |
|
314 |
|
315 |
+
with gr.Blocks() as block:
|
316 |
+
gr.Markdown("""
|
317 |
+
## Mapping OpenAlex-Queries
|
318 |
|
319 |
+
This is a tool to further interdisciplinary research – you are a neuroscientist who has used ..., What have the ... been doing with them.
|
320 |
+
You're a philosopher of science who wonders where the concept of a fitness landscape has appeared...
|
321 |
+
""")
|
322 |
+
|
323 |
+
with gr.Column():
|
324 |
+
text_input = gr.Textbox(label="OpenAlex Fulltext-Search")
|
325 |
+
sample_size_slider = gr.Slider(label="Sample Size", minimum=10, maximum=20000, step=10, value=1000)
|
326 |
+
reduce_sample_checkbox = gr.Checkbox(label="Reduce Sample Size", value=True)
|
327 |
+
new_btn = gr.Button("Run Query")
|
328 |
+
markdown = gr.Markdown(label="")
|
329 |
+
html = gr.HTML(label="HTML preview", show_label=True)
|
330 |
+
|
331 |
+
new_btn.click(fn=predict, inputs=[text_input, sample_size_slider, reduce_sample_checkbox], outputs=[markdown, html])
|
332 |
|
333 |
|
334 |
|