Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#import os
|
2 |
+
import requests
|
3 |
+
from pdf2image import convert_from_bytes
|
4 |
+
|
5 |
+
def download_pdf(url):
|
6 |
+
response = requests.get(url)
|
7 |
+
return response.content
|
8 |
+
|
9 |
+
def convert_pdf_to_images(pdf_bytes):
|
10 |
+
images = convert_from_bytes(pdf_bytes)
|
11 |
+
|
12 |
+
#if not os.path.exists(output_folder):
|
13 |
+
#os.makedirs(output_folder)
|
14 |
+
|
15 |
+
for i, image in enumerate(images):
|
16 |
+
image.save(f'image{i}.png')
|
17 |
+
|
18 |
+
# Use the functions
|
19 |
+
#url = 'http://example.com/path_to_your_pdf.pdf'
|
20 |
+
#pdf_bytes = download_pdf(url)
|
21 |
+
#output_folder = os.environ.get('HUGGINGFACE_CACHE', 'images')
|
22 |
+
convert_pdf_to_images('hoor.pdf', output_folder)
|