Reem333 commited on
Commit
1455e5f
·
verified ·
1 Parent(s): 34b702d

Delete app.py

Browse files
Files changed (1) hide show
  1. app.py +0 -99
app.py DELETED
@@ -1,99 +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 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
21
- truncated_text = text[:max_length]
22
-
23
- inputs = tokenizer(truncated_text, return_tensors="pt", padding=True, truncation=True, max_length=max_length)
24
- with torch.no_grad():
25
- outputs = model(**inputs)
26
- logits = outputs.logits
27
- predicted_class = torch.argmax(logits, dim=1).item()
28
- return predicted_class
29
- except Exception as e:
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
38
- 1: "#ff7f0e", # Level 2
39
- 2: "#2ca02c", # Level 3
40
- 3: "#1f77b4" # Level 4
41
- }
42
-
43
- st.set_page_config(page_title="Paper Citation Classifier", page_icon="logo.png")
44
-
45
- with st.sidebar:
46
- st.image("logo.png", width=70)
47
- st.markdown('<div style="position: absolute; left: 5px;"></div>', unsafe_allow_html=True)
48
-
49
- st.markdown("# Paper Citation Classifier")
50
- st.markdown("---")
51
- st.markdown("## About")
52
- st.markdown('''
53
- This is a tool to classify paper citations into different levels based on their number of citations.
54
- Powered by Fine-Tuned [Longformer model](https://huggingface.co/REEM-ALRASHIDI/LongFormer-Paper-Citaion-Classifier) with custom data.
55
- ''')
56
- st.markdown("### Class Levels:")
57
- st.markdown("- Level 1: Highly cited papers")
58
- st.markdown("- Level 2: Average cited papers")
59
- st.markdown("- Level 3: More cited papers")
60
- st.markdown("- Level 4: Low cited papers")
61
- st.markdown("---")
62
- st.markdown('Tabuk University')
63
-
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
-