Commit
·
e05ddac
1
Parent(s):
25de76d
Update app.py
Browse files
app.py
CHANGED
@@ -1,56 +1,56 @@
|
|
1 |
import streamlit as st
|
2 |
-
import torch
|
3 |
-
from transformers import AutoModelForSequenceClassification, AutoTokenizer
|
4 |
|
5 |
|
6 |
-
def combine_title_summary(title, summary):
|
7 |
-
|
8 |
|
9 |
|
10 |
-
tag2ind = {
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
}
|
16 |
|
17 |
|
18 |
-
@st.cache_resource
|
19 |
-
def load_model():
|
20 |
-
|
21 |
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
|
28 |
-
|
29 |
|
30 |
|
31 |
-
tokenizer, model = load_model()
|
32 |
|
33 |
|
34 |
-
def run_model(model, tokenizer, title, summary):
|
35 |
-
|
36 |
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
|
55 |
|
56 |
title = st.text_input(label="Title", value="")
|
@@ -62,5 +62,5 @@ if st.button("Submit"):
|
|
62 |
result = combine_title_summary(title, abstract)
|
63 |
st.success(result)
|
64 |
|
65 |
-
result = run_model(model, tokenizer, title, abstract)
|
66 |
-
st.success(result)
|
|
|
1 |
import streamlit as st
|
2 |
+
# import torch
|
3 |
+
# from transformers import AutoModelForSequenceClassification, AutoTokenizer
|
4 |
|
5 |
|
6 |
+
# def combine_title_summary(title, summary):
|
7 |
+
# return "title: " + title + " summary: " + summary
|
8 |
|
9 |
|
10 |
+
# tag2ind = {
|
11 |
+
# "bio": 0,
|
12 |
+
# "physics": 1,
|
13 |
+
# "math": 2,
|
14 |
+
# "cs": 3,
|
15 |
+
# }
|
16 |
|
17 |
|
18 |
+
# @st.cache_resource
|
19 |
+
# def load_model():
|
20 |
+
# device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
21 |
|
22 |
+
# # assert torch.cuda.is_available()
|
23 |
+
# tokenizer = AutoTokenizer.from_pretrained("distilbert/distilbert-base-cased")
|
24 |
+
# model = AutoModelForSequenceClassification.from_pretrained(
|
25 |
+
# "./my_model/checkpoint-513"
|
26 |
+
# ).to(device)
|
27 |
|
28 |
+
# return tokenizer, model
|
29 |
|
30 |
|
31 |
+
# tokenizer, model = load_model()
|
32 |
|
33 |
|
34 |
+
# def run_model(model, tokenizer, title, summary):
|
35 |
+
# text = combine_title_summary(title, summary)
|
36 |
|
37 |
+
# tokens_info = tokenizer(
|
38 |
+
# text,
|
39 |
+
# padding=False,
|
40 |
+
# truncation=True,
|
41 |
+
# return_tensors="pt",
|
42 |
+
# )
|
43 |
|
44 |
+
# model.eval()
|
45 |
+
# model.cpu()
|
46 |
+
# with torch.no_grad():
|
47 |
+
# out = model(**tokens_info)
|
48 |
+
# probs = torch.nn.functional.softmax(out.logits, dim=-1)[0]
|
49 |
|
50 |
+
# result = f"Text: `{text}`\nPrediction (prob): \n" + "\n".join(
|
51 |
+
# [f"{tag}={tag_prob}" for tag, tag_prob in zip(tag2ind, probs)]
|
52 |
+
# )
|
53 |
+
# return result
|
54 |
|
55 |
|
56 |
title = st.text_input(label="Title", value="")
|
|
|
62 |
result = combine_title_summary(title, abstract)
|
63 |
st.success(result)
|
64 |
|
65 |
+
# result = run_model(model, tokenizer, title, abstract)
|
66 |
+
# st.success(result)
|