File size: 1,750 Bytes
78f93e5
6e32aa8
 
78f93e5
 
2083f73
 
78f93e5
 
2083f73
 
 
 
 
 
78f93e5
 
e05ddac
 
 
78f93e5
e05ddac
 
 
 
 
78f93e5
e05ddac
78f93e5
 
e05ddac
78f93e5
 
e05ddac
 
78f93e5
e05ddac
 
 
 
 
 
78f93e5
e05ddac
 
 
 
 
78f93e5
e05ddac
 
 
 
78f93e5
 
 
 
 
 
 
 
 
 
 
e05ddac
 
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
import streamlit as st
# import torch
# from transformers import AutoModelForSequenceClassification, AutoTokenizer


def combine_title_summary(title, summary):
    return "title: " + title + " summary: " + summary


tag2ind = {
    "bio": 0,
    "physics": 1,
    "math": 2,
    "cs": 3,
}


# @st.cache_resource
# def load_model():
#     device = torch.device("cuda" if torch.cuda.is_available() else "cpu")

#     # assert torch.cuda.is_available()
#     tokenizer = AutoTokenizer.from_pretrained("distilbert/distilbert-base-cased")
#     model = AutoModelForSequenceClassification.from_pretrained(
#         "./my_model/checkpoint-513"
#     ).to(device)

#     return tokenizer, model


# tokenizer, model = load_model()


# def run_model(model, tokenizer, title, summary):
#     text = combine_title_summary(title, summary)

#     tokens_info = tokenizer(
#         text,
#         padding=False,
#         truncation=True,
#         return_tensors="pt",
#     )

#     model.eval()
#     model.cpu()
#     with torch.no_grad():
#         out = model(**tokens_info)
#         probs = torch.nn.functional.softmax(out.logits, dim=-1)[0]

#         result = f"Text: `{text}`\nPrediction (prob): \n" + "\n".join(
#             [f"{tag}={tag_prob}" for tag, tag_prob in zip(tag2ind, probs)]
#         )
#         return result


title = st.text_input(label="Title", value="")
abstract = st.text_input(label="Abstract", value="")
if st.button("Submit"):
    if title == "" and abstract == "":
        st.error("At least one of title or abstract must be provided")
    else:
        result = combine_title_summary(title, abstract)
        st.success(result)

        # result = run_model(model, tokenizer, title, abstract)
        # st.success(result)