Spaces:
Runtime error
Runtime error
File size: 4,145 Bytes
b90014b 93058e0 b90014b 93058e0 b90014b 93058e0 b90014b 93058e0 b90014b 93058e0 b90014b 93058e0 b90014b 7af8946 93058e0 7af8946 93058e0 b90014b 93058e0 b90014b 93058e0 b90014b 08edd6a 77cae10 08edd6a b90014b 93058e0 b90014b 7af8946 93058e0 b90014b 93058e0 b90014b 93058e0 |
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 |
import gradio as gr
import arxiv
import json
from model import predict_from_text
with open("./data/arxiv-label-dict.json", "r") as file:
subject_dict = json.loads(file.read())
def parse_id(input_id):
## Grab article title and true categories from arXiv
search = arxiv.Search(id_list=[input_id], max_results=1)
result = next(search.results())
raw_categories = result.categories
title = result.title
abstract = result.summary
subject_tags = ", ".join(
sorted(
[subject_dict[tag] for tag in raw_categories if tag in subject_dict.keys()]
)
)
return (title, subject_tags, abstract)
# def parse_title(input_title):
# query_title = input_title.replace(" ", "\%20")
# search = arxiv.Search(
# query=f"ti:\%22{query_title}\%22",
# sort_by=arxiv.SortCriterion.Relevance,
# sort_order=arxiv.SortOrder.Descending,
# max_results=1,
# )
# result = next(search.results())
# raw_categories = result.categories
# title = result.title
# with open("./data/arxiv-label-dict.json", "r") as file:
# subject_dict = json.loads(file.read())
# subject_tags = ", ".join(
# sorted(
# [subject_dict[tag] for tag in raw_categories if tag in subject_dict.keys()]
# )
# )
# return (title, subject_tags)
def outputs_from_id(input_id, threshold_probability):
title, true_tags, abstract = parse_id(input_id)
predicted_tags = predict_from_text(title, threshold_probability)
return title, predicted_tags, true_tags, abstract
# def outputs_from_title(input_title, threshold_probability):
# title, true_tags = parse_title(input_title)
# predicted_tags = predict_from_text(title, threshold_probability)
# return title, predicted_tags, true_tags
with gr.Blocks() as demo:
gr.Markdown(
"""# <center> Math Subject Classifier </center>
## <center> [Search](https://arxiv.org) for a math article and input its ID number below. </center>
"""
)
with gr.Row():
id_input = gr.Textbox(label="arXiv ID:", placeholder="XXXX.XXXXX")
id_title = gr.Textbox(label="Title of Input Article:")
id_predict = gr.Textbox(label="Predicted Subject Tags:")
id_true = gr.Textbox(label="Actual Subject Tags:")
threshold_probability = gr.Slider(
label="Minimum Confidence For Tag Prediction:", value=0.5, minimum=0, maximum=1
)
id_button = gr.Button("Get Predicted Subject Tags")
gr.Examples(
label="Try These Example Articles:",
examples=[
"1709.07343",
"2107.05105",
"1910.06441",
"2210.09246",
"2111.03188",
"1811.07007",
"2303.15347",
"2210.04580",
"1909.06032",
"2107.13138",
],
inputs=id_input,
)
gr.Markdown("### Article Abstract:")
article_abstract = gr.HTML()
# with gr.Tab("Predict by title"):
# with gr.Row():
# title_input = gr.Textbox(label="Input title")
# title_title = gr.Textbox(label="Title of closest match")
# title_predict = gr.Textbox(label="Predicted tags")
# title_true = gr.Textbox(label="True tags")
# title_button = gr.Button("Predict")
# gr.Examples(
# examples=[
# "Attention is all you need",
# "Etale cohomology of diamonds",
# "Stochastic Kahler geometry from random zeros to random metrics",
# "Scaling asymptotics for Szego kernels on Grauert tubes",
# "The Wave Trace and Birkhoff Billiards",
# ],
# inputs=title_input,
# )
id_button.click(
outputs_from_id,
inputs=[id_input, threshold_probability],
outputs=[id_title, id_predict, id_true, article_abstract],
)
# title_button.click(
# outputs_from_title,
# inputs=[title_input, threshold_probability],
# outputs=[title_title, title_predict, title_true],
# )
demo.launch(inbrowser=True)
|