Spaces:
Sleeping
Sleeping
File size: 2,264 Bytes
6cfce6c 123a600 53ac886 7c1c7bc 123a600 6cfce6c 53ac886 6cfce6c 0bd8a87 6cfce6c 708e41e 6cfce6c d13374d 6cfce6c 123a600 6cfce6c |
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 |
import streamlit as st
from transformers import pipeline
@st.cache_resource # кэширование
def load_model():
return pipeline("text-classification", model="voroninip/bert-paper-classifier-arxiv", top_k=None)
model = load_model()
def top_pct(preds, threshold=.95):
preds = sorted(preds, key=lambda x: -x["score"])
cum_score = 0
for i, item in enumerate(preds):
cum_score += item["score"]
if cum_score >= threshold:
break
preds = preds[:(i+1)]
return preds
def format_predictions(preds) -> str:
"""
Prepare predictions and their scores for printing to the user
"""
out = ""
for i, item in enumerate(preds):
out += f"{i+1}. {item['label']} (score {item['score']:.2f})\n"
return out
st.markdown("""
<div style='text-align: center;'>
<img src='https://info.arxiv.org/brand/images/brand-logo-primary.jpg' alt='Centered Image' width='300'/>
</div>
""", unsafe_allow_html=True)
st.markdown("""
<h2 style='text-align: center; color: #e80ad8; font-family: Arial;'>
🚀 arXiv paper categories predictor
</h2>
""", unsafe_allow_html=True)
# CSS to change the background of the entire app
background_color_css = """
<style>
.stApp {
background-color: black; /* #eefcfa */
}
</style>
"""
st.markdown("""
<p style='
color: white;
font-size: 20px;
font-family: "Courier New", monospace;
'>
Paste Title and Abstract of the paper and get most likely categories of the paper in the
<a href="https://arxiv.org/category_taxonomy" target="_blank" style="color: cyan; text-decoration: none;">
arXiv taxonomy
</a>
</p>
""", unsafe_allow_html=True)
title = st.text_input("Title", value="")
abstract = st.text_input("Abstract", value="")
query = title + '\n' + abstract
if title or abstract:
st.markdown("""
<br><br> <!-- Adds vertical space -->
<p style='
color: white;
font-size: 20px;
font-family: "Courier New", monospace;
'>
Most likely categories of the paper:
</p>
""", unsafe_allow_html=True)
result = format_predictions(top_pct(model(query)[0]))
st.write(result) |