Reem333 commited on
Commit
8bc93f3
·
verified ·
1 Parent(s): 0205253

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +1 -42
app.py CHANGED
@@ -7,14 +7,6 @@ import os
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
@@ -97,37 +89,4 @@ if option == "Text":
97
  unsafe_allow_html=True
98
  )
99
  else:
100
- st.text(label)
101
-
102
- elif option == "PDF":
103
- uploaded_file = st.file_uploader("Upload a PDF file", type=["pdf"])
104
-
105
- if uploaded_file is not None:
106
- with st.spinner("Processing PDF..."):
107
- file_path = os.path.join(uploaded_files_dir, uploaded_file.name)
108
- with open(file_path, "wb") as f:
109
- f.write(uploaded_file.getbuffer())
110
- st.success("File uploaded successfully.")
111
- st.text(f"File Path: {file_path}")
112
-
113
- file_text = extract_text_from_pdf(file_path)
114
- st.text("Extracted Text:")
115
- st.text(file_text)
116
-
117
- if st.button("Predict from PDF Text"):
118
- if not file_text.strip():
119
- st.warning("Please upload a PDF with text content.")
120
- else:
121
- with st.spinner("Predicting..."):
122
- predicted_class = predict_class(file_text)
123
- if predicted_class is not None:
124
- class_labels = ["Level 1", "Level 2", "Level 3", "Level 4"]
125
- st.text("**Predicted Class:**")
126
- for i, label in enumerate(class_labels):
127
- if i == predicted_class:
128
- st.markdown(
129
- f'<div style="background-color: {class_colors[predicted_class]}; padding: 10px; border-radius: 5px; color: white; font-weight: bold;">{label}</div>',
130
- unsafe_allow_html=True
131
- )
132
- else:
133
- st.text(label)
 
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
 
89
  unsafe_allow_html=True
90
  )
91
  else:
92
+ st.text(label)