File size: 1,550 Bytes
f4107c5
 
5a69625
f4107c5
 
 
44ee98d
f4107c5
 
 
 
 
 
 
 
 
 
 
44ee98d
f4107c5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a8cb422
 
f4107c5
 
717ed87
756780e
f4107c5
5a69625
 
 
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
import streamlit as st
import arxiv
from inference import top_95_labels, load_model  # Replace with your actual module

@st.cache_resource
def get_model():
    return load_model("kalinin-a-i/ml2-hw4", "class2name.joblib")

def get_arxiv_article_info(url):
    """Extracts title and abstract from an arXiv article link."""
    paper_id = url.split("/abs/")[-1]
    search = arxiv.Search(id_list=[paper_id])
    
    for result in search.results():
        return result.title, result.summary
    return None, None

# Load model once
pipe, class2name = get_model()

st.title("ArXiv Article Classifier")

# Input method selection
input_method = st.radio("Select input method:", ("ArXiv Link", "Manual Input"))

title, abstract = None, None

if input_method == "ArXiv Link":
    arxiv_url = st.text_input("Enter ArXiv article link:")
    if st.button("Classify"):
        if arxiv_url:
            title, abstract = get_arxiv_article_info(arxiv_url)
        else:
            st.error("Please enter a valid ArXiv link.")
elif input_method == "Manual Input":
    title = st.text_input("Enter Article Title:")
    abstract = st.text_area("Enter Article Abstract:")
    if st.button("Classify"):
        if not title:
            st.error("Please provide title")

# Classification and output
if title:
    categories = top_95_labels(pipe, class2name, title, abstract)  # Assuming classify returns a list of labels
    st.write(f"### Title: {title}")
    st.write("**Predicted Categories:**")
    for category in categories:
        st.write(f"- {category}")