Spaces:
Runtime error
Runtime error
Delete app.py
Browse files
app.py
DELETED
@@ -1,88 +0,0 @@
|
|
1 |
-
import streamlit as st
|
2 |
-
import torch
|
3 |
-
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
4 |
-
import fitz
|
5 |
-
import os
|
6 |
-
|
7 |
-
model = AutoModelForSequenceClassification.from_pretrained("Reem333/Citaion-Classifier")
|
8 |
-
tokenizer = AutoTokenizer.from_pretrained("allenai/longformer-base-4096")
|
9 |
-
|
10 |
-
def predict_class(text):
|
11 |
-
try:
|
12 |
-
max_length = 4096
|
13 |
-
truncated_text = text[:max_length]
|
14 |
-
|
15 |
-
inputs = tokenizer(truncated_text, return_tensors="pt", padding=True, truncation=True, max_length=max_length)
|
16 |
-
with torch.no_grad():
|
17 |
-
outputs = model(**inputs)
|
18 |
-
logits = outputs.logits
|
19 |
-
predicted_class = torch.argmax(logits, dim=1).item()
|
20 |
-
return predicted_class
|
21 |
-
except Exception as e:
|
22 |
-
st.error(f"Error during prediction: {e}")
|
23 |
-
return None
|
24 |
-
|
25 |
-
|
26 |
-
class_colors = {
|
27 |
-
0: "#2ca02c", # Level 1
|
28 |
-
1: "#ff7f0e", # Level 2
|
29 |
-
2: "#ffff00", # Level 3
|
30 |
-
3: "#d62728" # Level 4
|
31 |
-
}
|
32 |
-
|
33 |
-
st.set_page_config(page_title="Paper Citation Classifier", page_icon="logo.png")
|
34 |
-
|
35 |
-
with st.sidebar:
|
36 |
-
st.image("logo.png", width=70)
|
37 |
-
st.markdown('<div style="position: absolute; left: 5px;"></div>', unsafe_allow_html=True)
|
38 |
-
|
39 |
-
st.markdown("# Paper Citation Classifier")
|
40 |
-
st.markdown("---")
|
41 |
-
st.markdown("## About")
|
42 |
-
st.markdown('''
|
43 |
-
This is a tool to classify paper citations into different levels based on their number of citations.
|
44 |
-
Powered by Fine-Tuned [Longformer model](https://huggingface.co/REEM-ALRASHIDI/LongFormer-Paper-Citaion-Classifier) with custom data.
|
45 |
-
''')
|
46 |
-
st.markdown("### Class Levels:")
|
47 |
-
st.markdown("- Level 1: Highly cited papers")
|
48 |
-
st.markdown("- Level 2: Average cited papers")
|
49 |
-
st.markdown("- Level 3: More cited papers")
|
50 |
-
st.markdown("- Level 4: Low cited papers")
|
51 |
-
st.markdown("---")
|
52 |
-
st.markdown('Tabuk University')
|
53 |
-
|
54 |
-
st.title("Check Your Paper Now!")
|
55 |
-
|
56 |
-
|
57 |
-
title_input = st.text_area("Enter Title:")
|
58 |
-
abstract_input = st.text_area("Enter Abstract:")
|
59 |
-
full_text_input = st.text_area("Enter Full Text:")
|
60 |
-
affiliations_input = st.text_area("Enter Affiliations:")
|
61 |
-
keywords_input = st.text_area("Enter Keywords:")
|
62 |
-
options=["Nursing", "Physics", "Maths", "Chemical", "Nuclear", "Engineering" ,"Other"]
|
63 |
-
|
64 |
-
selected_category = st.selectbox("Select WoS categories:", options, index= None)
|
65 |
-
if selected_category == "Other":
|
66 |
-
custom_category = st.text_input("Enter custom category:")
|
67 |
-
selected_category = custom_category if custom_category else "Other"
|
68 |
-
|
69 |
-
combined_text = f"{title_input} [SEP] {keywords_input} [SEP] {abstract_input} [SEP] {selected_category} [SEP] {affiliations_input} [SEP] {' [SEP] '.join(full_text_input)}"
|
70 |
-
|
71 |
-
if st.button("Predict"):
|
72 |
-
if not any([title_input, abstract_input,keywords_input, full_text_input, affiliations_input]):
|
73 |
-
st.warning("Please enter paper text.")
|
74 |
-
else:
|
75 |
-
with st.spinner("Predicting..."):
|
76 |
-
predicted_class = predict_class(combined_text)
|
77 |
-
if predicted_class is not None:
|
78 |
-
class_labels = ["Level 1", "Level 2", "Level 3", "Level 4"]
|
79 |
-
|
80 |
-
st.text("Predicted Class:")
|
81 |
-
for i, label in enumerate(class_labels):
|
82 |
-
if i == predicted_class:
|
83 |
-
st.markdown(
|
84 |
-
f'<div style="background-color: {class_colors[predicted_class]}; padding: 10px; border-radius: 5px; color: white; font-weight: bold;">{label}</div>',
|
85 |
-
unsafe_allow_html=True
|
86 |
-
)
|
87 |
-
else:
|
88 |
-
st.text(label)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|