Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -67,11 +67,7 @@ def process_pdf(file):
|
|
| 67 |
st.error(f"Error on page {i + 1}: {e}")
|
| 68 |
finally:
|
| 69 |
os.remove(temp_pdf_path)
|
| 70 |
-
|
| 71 |
-
with tempfile.NamedTemporaryFile(suffix=".txt", delete=False) as temp_txt:
|
| 72 |
-
temp_txt.write(text.encode("utf-8"))
|
| 73 |
-
temp_txt_path = temp_txt.name
|
| 74 |
-
return temp_txt_path
|
| 75 |
|
| 76 |
|
| 77 |
# Function to generate thumbnail from PDF
|
|
@@ -186,9 +182,10 @@ elif selection == "PDF Transcriber":
|
|
| 186 |
output_file = process_pdf(uploaded_file)
|
| 187 |
if output_file:
|
| 188 |
st.success("Text extraction complete!")
|
| 189 |
-
st.text_area("Extracted Text", open(output_file).read(), height=400)
|
| 190 |
output_file_name = generate_unique_filename(uploaded_file.name, "(T)", ".txt")
|
| 191 |
-
|
|
|
|
| 192 |
os.remove(output_file)
|
| 193 |
else:
|
| 194 |
st.error("Could not process the PDF, please try again")
|
|
|
|
| 67 |
st.error(f"Error on page {i + 1}: {e}")
|
| 68 |
finally:
|
| 69 |
os.remove(temp_pdf_path)
|
| 70 |
+
return text
|
|
|
|
|
|
|
|
|
|
|
|
|
| 71 |
|
| 72 |
|
| 73 |
# Function to generate thumbnail from PDF
|
|
|
|
| 182 |
output_file = process_pdf(uploaded_file)
|
| 183 |
if output_file:
|
| 184 |
st.success("Text extraction complete!")
|
| 185 |
+
st.text_area("Extracted Text", open(output_file, encoding="utf-8").read(), height=400)
|
| 186 |
output_file_name = generate_unique_filename(uploaded_file.name, "(T)", ".txt")
|
| 187 |
+
with open(output_file, "rb") as f:
|
| 188 |
+
st.download_button("Download Extracted Text", f, file_name=output_file_name, mime="text/plain")
|
| 189 |
os.remove(output_file)
|
| 190 |
else:
|
| 191 |
st.error("Could not process the PDF, please try again")
|