Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -7,6 +7,14 @@ import os
|
|
| 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
|
|
@@ -22,6 +30,8 @@ def predict_class(text):
|
|
| 22 |
st.error(f"Error during prediction: {e}")
|
| 23 |
return None
|
| 24 |
|
|
|
|
|
|
|
| 25 |
|
| 26 |
class_colors = {
|
| 27 |
0: "#d62728", # Level 1
|
|
@@ -54,36 +64,36 @@ with st.sidebar:
|
|
| 54 |
st.title("Check Your Paper Now!")
|
| 55 |
|
| 56 |
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 64 |
|
| 65 |
-
|
| 66 |
-
if selected_category == "Other":
|
| 67 |
-
custom_category = st.text_input("Enter custom category:")
|
| 68 |
-
selected_category = custom_category if custom_category else "Other"
|
| 69 |
|
| 70 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 71 |
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
|
|
|
| 80 |
|
| 81 |
-
st.text("Predicted Class:")
|
| 82 |
-
for i, label in enumerate(class_labels):
|
| 83 |
-
if i == predicted_class:
|
| 84 |
-
st.markdown(
|
| 85 |
-
f'<div style="background-color: {class_colors[predicted_class]}; padding: 10px; border-radius: 5px; color: white; font-weight: bold;">{label}</div>',
|
| 86 |
-
unsafe_allow_html=True
|
| 87 |
-
)
|
| 88 |
-
else:
|
| 89 |
-
st.text(label)
|
|
|
|
| 7 |
model = AutoModelForSequenceClassification.from_pretrained("Reem333/Citaion-Classifier")
|
| 8 |
tokenizer = AutoTokenizer.from_pretrained("allenai/longformer-base-4096")
|
| 9 |
|
| 10 |
+
def extract_text_from_pdf(file_path):
|
| 11 |
+
text = ''
|
| 12 |
+
with fitz.open(file_path) as pdf_document:
|
| 13 |
+
for page_number in range(pdf_document.page_count):
|
| 14 |
+
page = pdf_document.load_page(page_number)
|
| 15 |
+
text += page.get_text()
|
| 16 |
+
return text
|
| 17 |
+
|
| 18 |
def predict_class(text):
|
| 19 |
try:
|
| 20 |
max_length = 4096
|
|
|
|
| 30 |
st.error(f"Error during prediction: {e}")
|
| 31 |
return None
|
| 32 |
|
| 33 |
+
uploaded_files_dir = "uploaded_files"
|
| 34 |
+
os.makedirs(uploaded_files_dir, exist_ok=True)
|
| 35 |
|
| 36 |
class_colors = {
|
| 37 |
0: "#d62728", # Level 1
|
|
|
|
| 64 |
st.title("Check Your Paper Now!")
|
| 65 |
|
| 66 |
|
| 67 |
+
title_input = st.text_area("Enter Title:")
|
| 68 |
+
abstract_input = st.text_area("Enter Abstract:")
|
| 69 |
+
full_text_input = st.text_area("Enter Full Text:")
|
| 70 |
+
affiliations_input = st.text_area("Enter Affiliations:")
|
| 71 |
+
keywords_input = st.text_area("Enter Keywords:")
|
| 72 |
+
options=["Nursing", "Physics", "Maths", "Chemical", "Nuclear", "Engineering" ,"Other"]
|
| 73 |
+
|
| 74 |
+
selected_category = st.selectbox("Select WoS categories:", options, index= None)
|
| 75 |
+
if selected_category == "Other":
|
| 76 |
+
custom_category = st.text_input("Enter custom category:")
|
| 77 |
+
selected_category = custom_category if custom_category else "Other"
|
| 78 |
|
| 79 |
+
combined_text = f"{title_input} [SEP] {keywords_input} [SEP] {abstract_input} [SEP] {selected_category} [SEP] {affiliations_input} [SEP] {' [SEP] '.join(full_text_input)}"
|
|
|
|
|
|
|
|
|
|
| 80 |
|
| 81 |
+
if st.button("Predict"):
|
| 82 |
+
if not any([title_input, abstract_input,keywords_input, full_text_input, affiliations_input]):
|
| 83 |
+
st.warning("Please enter paper text.")
|
| 84 |
+
else:
|
| 85 |
+
with st.spinner("Predicting..."):
|
| 86 |
+
predicted_class = predict_class(combined_text)
|
| 87 |
+
if predicted_class is not None:
|
| 88 |
+
class_labels = ["Level 1", "Level 2", "Level 3", "Level 4"]
|
| 89 |
|
| 90 |
+
st.text("Predicted Class:")
|
| 91 |
+
for i, label in enumerate(class_labels):
|
| 92 |
+
if i == predicted_class:
|
| 93 |
+
st.markdown(
|
| 94 |
+
f'<div style="background-color: {class_colors[predicted_class]}; padding: 10px; border-radius: 5px; color: white; font-weight: bold;">{label}</div>',
|
| 95 |
+
unsafe_allow_html=True
|
| 96 |
+
)
|
| 97 |
+
else:
|
| 98 |
+
st.text(label)
|
| 99 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|