Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
@@ -20,7 +20,6 @@ import uvicorn
|
|
20 |
import gradio as gr
|
21 |
from datetime import datetime
|
22 |
import sys
|
23 |
-
from urllib.parse import urlparse, parse_qs, unquote
|
24 |
|
25 |
|
26 |
|
@@ -75,51 +74,6 @@ print(f"Imports are done: {time.strftime('%Y-%m-%d %H:%M:%S')}")
|
|
75 |
|
76 |
|
77 |
|
78 |
-
# def openalex_url_to_pyalex_query(url):
|
79 |
-
# """
|
80 |
-
# Convert an OpenAlex search URL to a pyalex query.
|
81 |
-
|
82 |
-
# Args:
|
83 |
-
# url (str): The OpenAlex search URL.
|
84 |
-
|
85 |
-
# Returns:
|
86 |
-
# tuple: (Works object, dict of parameters)
|
87 |
-
# """
|
88 |
-
# parsed_url = urlparse(url)
|
89 |
-
# query_params = parse_qs(parsed_url.query)
|
90 |
-
|
91 |
-
# # Initialize the Works object
|
92 |
-
# query = Works()
|
93 |
-
|
94 |
-
# # Handle filters
|
95 |
-
# if 'filter' in query_params:
|
96 |
-
# filters = query_params['filter'][0].split(',')
|
97 |
-
# for f in filters:
|
98 |
-
# if ':' in f:
|
99 |
-
# key, value = f.split(':', 1)
|
100 |
-
# if key == 'default.search':
|
101 |
-
# query = query.search(value)
|
102 |
-
# else:
|
103 |
-
# query = query.filter(**{key: value})
|
104 |
-
|
105 |
-
# # Handle sort
|
106 |
-
# if 'sort' in query_params:
|
107 |
-
# sort_params = query_params['sort'][0].split(',')
|
108 |
-
# for s in sort_params:
|
109 |
-
# if s.startswith('-'):
|
110 |
-
# query = query.sort(**{s[1:]: 'desc'})
|
111 |
-
# else:
|
112 |
-
# query = query.sort(**{s: 'asc'})
|
113 |
-
|
114 |
-
# # Handle other parameters
|
115 |
-
# params = {}
|
116 |
-
# for key in ['page', 'per-page', 'sample', 'seed']:
|
117 |
-
# if key in query_params:
|
118 |
-
# params[key] = query_params[key][0]
|
119 |
-
|
120 |
-
# return query, params
|
121 |
-
|
122 |
-
|
123 |
def openalex_url_to_pyalex_query(url):
|
124 |
"""
|
125 |
Convert an OpenAlex search URL to a pyalex query.
|
@@ -143,7 +97,7 @@ def openalex_url_to_pyalex_query(url):
|
|
143 |
if ':' in f:
|
144 |
key, value = f.split(':', 1)
|
145 |
if key == 'default.search':
|
146 |
-
query = query.search(
|
147 |
else:
|
148 |
query = query.filter(**{key: value})
|
149 |
|
@@ -151,12 +105,10 @@ def openalex_url_to_pyalex_query(url):
|
|
151 |
if 'sort' in query_params:
|
152 |
sort_params = query_params['sort'][0].split(',')
|
153 |
for s in sort_params:
|
154 |
-
if '
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
else:
|
159 |
-
query = query.sort(field)
|
160 |
|
161 |
# Handle other parameters
|
162 |
params = {}
|
@@ -167,10 +119,6 @@ def openalex_url_to_pyalex_query(url):
|
|
167 |
return query, params
|
168 |
|
169 |
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
def invert_abstract(inv_index):
|
175 |
if inv_index is not None:
|
176 |
l_inv = [(w, p) for w, pos in inv_index.items() for p in pos]
|
@@ -476,7 +424,6 @@ def predict(text_input, sample_size_slider, reduce_sample_checkbox,sample_reduct
|
|
476 |
with gr.Blocks() as block:
|
477 |
gr.Markdown("""
|
478 |
## Mapping OpenAlex-Queries
|
479 |
-
|
480 |
Enter the URL to an OpenAlex-search below. It will take a few minutes, but then the result will be projected onto a map of the OA database as a whole.
|
481 |
""")
|
482 |
|
@@ -492,8 +439,8 @@ with gr.Blocks() as block:
|
|
492 |
|
493 |
|
494 |
new_btn = gr.Button("Run Query",variant='primary')
|
495 |
-
markdown = gr.Markdown(label=""
|
496 |
-
html = gr.HTML(label="
|
497 |
|
498 |
new_btn.click(fn=predict, inputs=[text_input, sample_size_slider, reduce_sample_checkbox,sample_reduction_method], outputs=[markdown, html])
|
499 |
|
@@ -554,4 +501,4 @@ if __name__ == "__main__":
|
|
554 |
# run the app with
|
555 |
# python app.py
|
556 |
# or
|
557 |
-
# uvicorn "app:app" --host "0.0.0.0" --port 7860 --reload
|
|
|
20 |
import gradio as gr
|
21 |
from datetime import datetime
|
22 |
import sys
|
|
|
23 |
|
24 |
|
25 |
|
|
|
74 |
|
75 |
|
76 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
77 |
def openalex_url_to_pyalex_query(url):
|
78 |
"""
|
79 |
Convert an OpenAlex search URL to a pyalex query.
|
|
|
97 |
if ':' in f:
|
98 |
key, value = f.split(':', 1)
|
99 |
if key == 'default.search':
|
100 |
+
query = query.search(value)
|
101 |
else:
|
102 |
query = query.filter(**{key: value})
|
103 |
|
|
|
105 |
if 'sort' in query_params:
|
106 |
sort_params = query_params['sort'][0].split(',')
|
107 |
for s in sort_params:
|
108 |
+
if s.startswith('-'):
|
109 |
+
query = query.sort(**{s[1:]: 'desc'})
|
110 |
+
else:
|
111 |
+
query = query.sort(**{s: 'asc'})
|
|
|
|
|
112 |
|
113 |
# Handle other parameters
|
114 |
params = {}
|
|
|
119 |
return query, params
|
120 |
|
121 |
|
|
|
|
|
|
|
|
|
122 |
def invert_abstract(inv_index):
|
123 |
if inv_index is not None:
|
124 |
l_inv = [(w, p) for w, pos in inv_index.items() for p in pos]
|
|
|
424 |
with gr.Blocks() as block:
|
425 |
gr.Markdown("""
|
426 |
## Mapping OpenAlex-Queries
|
|
|
427 |
Enter the URL to an OpenAlex-search below. It will take a few minutes, but then the result will be projected onto a map of the OA database as a whole.
|
428 |
""")
|
429 |
|
|
|
439 |
|
440 |
|
441 |
new_btn = gr.Button("Run Query",variant='primary')
|
442 |
+
markdown = gr.Markdown(label="")
|
443 |
+
html = gr.HTML(label="HTML preview", show_label=True)
|
444 |
|
445 |
new_btn.click(fn=predict, inputs=[text_input, sample_size_slider, reduce_sample_checkbox,sample_reduction_method], outputs=[markdown, html])
|
446 |
|
|
|
501 |
# run the app with
|
502 |
# python app.py
|
503 |
# or
|
504 |
+
# uvicorn "app:app" --host "0.0.0.0" --port 7860 --reload
|