Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -44,6 +44,14 @@ class_colors = {
|
|
44 |
3: "#d62728" # Level 4
|
45 |
}
|
46 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
47 |
st.title("Paper Citation Classifier")
|
48 |
|
49 |
option = st.radio("Select input type:", ("Text", "PDF"))
|
@@ -58,36 +66,49 @@ if option == "Text":
|
|
58 |
combined_text = f"{abstract_input} [SEP] {full_text_input} [SEP] {affiliations_input}"
|
59 |
|
60 |
if st.button("Predict"):
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
69 |
|
70 |
elif option == "PDF":
|
71 |
uploaded_file = st.file_uploader("Upload a PDF file", type=["pdf"])
|
72 |
|
73 |
if uploaded_file is not None:
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
|
|
83 |
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
44 |
3: "#d62728" # Level 4
|
45 |
}
|
46 |
|
47 |
+
# Define information for each level
|
48 |
+
class_info = {
|
49 |
+
0: "Highly cited",
|
50 |
+
1: "Average citations",
|
51 |
+
2: "More citations",
|
52 |
+
3: "Low citations"
|
53 |
+
}
|
54 |
+
|
55 |
st.title("Paper Citation Classifier")
|
56 |
|
57 |
option = st.radio("Select input type:", ("Text", "PDF"))
|
|
|
66 |
combined_text = f"{abstract_input} [SEP] {full_text_input} [SEP] {affiliations_input}"
|
67 |
|
68 |
if st.button("Predict"):
|
69 |
+
with st.spinner("Predicting..."):
|
70 |
+
predicted_class = predict_class(combined_text)
|
71 |
+
if predicted_class is not None:
|
72 |
+
class_labels = ["Level 1", "Level 2", "Level 3", "Level 4"]
|
73 |
+
st.text("Predicted Class:")
|
74 |
+
for i, label in enumerate(class_labels):
|
75 |
+
if i == predicted_class:
|
76 |
+
st.markdown(
|
77 |
+
f'<div style="background-color: {class_colors[predicted_class]}; padding: 10px; border-radius: 5px; color: white; font-weight: bold;">{label}</div>',
|
78 |
+
unsafe_allow_html=True
|
79 |
+
)
|
80 |
+
st.text(class_info[predicted_class])
|
81 |
+
else:
|
82 |
+
st.text(label)
|
83 |
|
84 |
elif option == "PDF":
|
85 |
uploaded_file = st.file_uploader("Upload a PDF file", type=["pdf"])
|
86 |
|
87 |
if uploaded_file is not None:
|
88 |
+
with st.spinner("Processing PDF..."):
|
89 |
+
file_path = os.path.join(uploaded_files_dir, uploaded_file.name)
|
90 |
+
with open(file_path, "wb") as f:
|
91 |
+
f.write(uploaded_file.getbuffer())
|
92 |
+
st.success("File uploaded successfully.")
|
93 |
+
st.text(f"File Path: {file_path}")
|
94 |
+
|
95 |
+
file_text = extract_text_from_pdf(file_path)
|
96 |
+
st.text("Extracted Text:")
|
97 |
+
st.text(file_text)
|
98 |
|
99 |
+
# Provide an option to predict from PDF text
|
100 |
+
if st.button("Predict from PDF Text"):
|
101 |
+
with st.spinner("Predicting..."):
|
102 |
+
predicted_class = predict_class(file_text)
|
103 |
+
if predicted_class is not None:
|
104 |
+
class_labels = ["Level 1", "Level 2", "Level 3", "Level 4"]
|
105 |
+
st.text("Predicted Class:")
|
106 |
+
for i, label in enumerate(class_labels):
|
107 |
+
if i == predicted_class:
|
108 |
+
st.markdown(
|
109 |
+
f'<div style="background-color: {class_colors[predicted_class]}; padding: 10px; border-radius: 5px; color: white; font-weight: bold;">{label}</div>',
|
110 |
+
unsafe_allow_html=True
|
111 |
+
)
|
112 |
+
st.text(class_info[predicted_class])
|
113 |
+
else:
|
114 |
+
st.text(label)
|