Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -15,6 +15,7 @@ if torch.cuda.is_available():
|
|
15 |
validation_results = json.load(open('validation_results.json'))
|
16 |
scores, thresholds, precisions, recalls = validation_results['scores'], validation_results['thresholds'], validation_results['precisions'], validation_results['recalls']
|
17 |
|
|
|
18 |
def get_threshold_precision(score_):
|
19 |
for score, threshold, precision, recall in zip(scores, thresholds, precisions, recalls):
|
20 |
if score_ < score:
|
@@ -24,6 +25,34 @@ def get_threshold_precision(score_):
|
|
24 |
prev_threshold = score_
|
25 |
return prev_threshold, prev_precision, prev_recall
|
26 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
27 |
def normalize_spaces(text):
|
28 |
return re.sub(r'\s+', ' ', text).strip()
|
29 |
|
@@ -69,10 +98,14 @@ example_abstract = "Chatbots such as GPT-4 and ChatGPT are now serving millions
|
|
69 |
|
70 |
iface = gr.Interface(
|
71 |
fn=predict,
|
72 |
-
inputs=[gr.Textbox(
|
|
|
|
|
|
|
|
|
73 |
outputs=[gr.Textbox(label="Predicted Score"), gr.Textbox(label="Predicted Selection Probability")],
|
74 |
title="Paper Selection Prediction",
|
75 |
-
description="Predict if @_akhaliq will select your paper. Enter the title, authors, and abstract of your paper.",
|
76 |
live=False,
|
77 |
)
|
78 |
|
|
|
15 |
validation_results = json.load(open('validation_results.json'))
|
16 |
scores, thresholds, precisions, recalls = validation_results['scores'], validation_results['thresholds'], validation_results['precisions'], validation_results['recalls']
|
17 |
|
18 |
+
|
19 |
def get_threshold_precision(score_):
|
20 |
for score, threshold, precision, recall in zip(scores, thresholds, precisions, recalls):
|
21 |
if score_ < score:
|
|
|
25 |
prev_threshold = score_
|
26 |
return prev_threshold, prev_precision, prev_recall
|
27 |
|
28 |
+
def extract_arxiv_id(input_text):
|
29 |
+
if 'arxiv.org' in input_text:
|
30 |
+
parsed_url = urlparse(input_text)
|
31 |
+
query = parse_qs(parsed_url.query)
|
32 |
+
path_parts = parsed_url.path.split('/')
|
33 |
+
if 'id_list' in query:
|
34 |
+
return query['id_list'][0]
|
35 |
+
elif path_parts[-2] in ['abs', 'pdf']:
|
36 |
+
return path_parts[-1].replace('.pdf', '')
|
37 |
+
return input_text
|
38 |
+
|
39 |
+
def fetch_arxiv_data(arxiv_id):
|
40 |
+
time.sleep(3) # Comply with arXiv API terms of usage
|
41 |
+
query_url = f'http://export.arxiv.org/api/query?id_list={arxiv_id}'
|
42 |
+
response = feedparser.parse(query_url)
|
43 |
+
if response.entries:
|
44 |
+
entry = response.entries[0]
|
45 |
+
title = entry.title
|
46 |
+
authors = ', '.join(author.name for author in entry.authors)
|
47 |
+
abstract = entry.summary
|
48 |
+
return title, authors, abstract
|
49 |
+
return "", "", ""
|
50 |
+
|
51 |
+
def update_fields(url_or_id):
|
52 |
+
arxiv_id = extract_arxiv_id(url_or_id)
|
53 |
+
title, authors, abstract = fetch_arxiv_data(arxiv_id)
|
54 |
+
return title, authors, abstract
|
55 |
+
|
56 |
def normalize_spaces(text):
|
57 |
return re.sub(r'\s+', ' ', text).strip()
|
58 |
|
|
|
98 |
|
99 |
iface = gr.Interface(
|
100 |
fn=predict,
|
101 |
+
inputs=[gr.Textbox(label="Paper Title", placeholder="Enter paper title", value=example_title),
|
102 |
+
gr.Textbox(label="Authors (separated by comma)", placeholder="Enter authors (separated by comma)", value=example_authors),
|
103 |
+
gr.TextArea(label="Abstract", placeholder="Enter abstract", value=example_abstract),
|
104 |
+
gr.Textbox(label="[Optional] Autofill using arXiv URL/ID", placeholder="[Optional] Autofill using arXiv URL/ID", on_change=update_fields, change_elements=["title", "authors", "abstract"]),
|
105 |
+
],
|
106 |
outputs=[gr.Textbox(label="Predicted Score"), gr.Textbox(label="Predicted Selection Probability")],
|
107 |
title="Paper Selection Prediction",
|
108 |
+
description="Predict if @_akhaliq will select your paper. Enter the title, authors, and abstract of your paper, or enter an arXiv URL/ID.",
|
109 |
live=False,
|
110 |
)
|
111 |
|