Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -49,7 +49,7 @@ def get_face_locations(binary_data):
|
|
49 |
print(3)
|
50 |
return face_locations
|
51 |
|
52 |
-
def
|
53 |
# List to store page information
|
54 |
pages_info = []
|
55 |
|
@@ -57,13 +57,18 @@ def seperate_image_text_from_pdf(pdf_url):
|
|
57 |
response = requests.get(pdf_url)
|
58 |
|
59 |
if response.status_code == 200:
|
60 |
-
# Create a temporary
|
61 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
62 |
tmp_file.write(response.content)
|
63 |
-
tmp_file_path = tmp_file.name
|
64 |
|
65 |
# Open the PDF
|
66 |
-
pdf = fitz.open(
|
67 |
|
68 |
# Iterate through each page
|
69 |
for page_num in range(len(pdf)):
|
@@ -96,9 +101,9 @@ def seperate_image_text_from_pdf(pdf_url):
|
|
96 |
# Close the PDF
|
97 |
pdf.close()
|
98 |
|
99 |
-
# Clean up the temporary
|
100 |
-
|
101 |
-
os.
|
102 |
else:
|
103 |
print("Failed to fetch the PDF from the URL.")
|
104 |
|
@@ -148,16 +153,18 @@ def separate_audio_from_video(video_url):
|
|
148 |
# Extract audio
|
149 |
audio = video.audio
|
150 |
|
151 |
-
# Create a temporary
|
152 |
-
|
153 |
-
|
|
|
|
|
154 |
|
155 |
-
|
156 |
-
|
157 |
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
|
162 |
return audio_bytes
|
163 |
|
|
|
49 |
print(3)
|
50 |
return face_locations
|
51 |
|
52 |
+
def separate_image_text_from_pdf(pdf_url):
|
53 |
# List to store page information
|
54 |
pages_info = []
|
55 |
|
|
|
57 |
response = requests.get(pdf_url)
|
58 |
|
59 |
if response.status_code == 200:
|
60 |
+
# Create a temporary directory to store the PDF data
|
61 |
+
temp_dir = tempfile.mkdtemp()
|
62 |
+
|
63 |
+
# Define the temporary file path for the PDF
|
64 |
+
temp_pdf_path = os.path.join(temp_dir, "temp.pdf")
|
65 |
+
|
66 |
+
# Write the PDF data to the temporary file
|
67 |
+
with open(temp_pdf_path, "wb") as tmp_file:
|
68 |
tmp_file.write(response.content)
|
|
|
69 |
|
70 |
# Open the PDF
|
71 |
+
pdf = fitz.open(temp_pdf_path)
|
72 |
|
73 |
# Iterate through each page
|
74 |
for page_num in range(len(pdf)):
|
|
|
101 |
# Close the PDF
|
102 |
pdf.close()
|
103 |
|
104 |
+
# Clean up the temporary files
|
105 |
+
os.unlink(temp_pdf_path)
|
106 |
+
os.rmdir(temp_dir)
|
107 |
else:
|
108 |
print("Failed to fetch the PDF from the URL.")
|
109 |
|
|
|
153 |
# Extract audio
|
154 |
audio = video.audio
|
155 |
|
156 |
+
# Create a temporary directory to store temporary files
|
157 |
+
temp_dir = tempfile.mkdtemp()
|
158 |
+
|
159 |
+
# Define the temporary file path for the audio
|
160 |
+
temp_audio_filename = os.path.join(temp_dir, "audio.wav")
|
161 |
|
162 |
+
# Write the audio data to the temporary file
|
163 |
+
audio.write_audiofile(temp_audio_filename)
|
164 |
|
165 |
+
# Read the audio data from the temporary file as bytes
|
166 |
+
with open(temp_audio_filename, "rb") as f:
|
167 |
+
audio_bytes = f.read()
|
168 |
|
169 |
return audio_bytes
|
170 |
|