Spaces:
Sleeping
Sleeping
add docx file download
Browse files
app.py
CHANGED
|
@@ -8,6 +8,7 @@ import zipfile
|
|
| 8 |
import tempfile
|
| 9 |
os.system("apt-get install poppler-utils")
|
| 10 |
import datetime
|
|
|
|
| 11 |
|
| 12 |
# Function to process a list of PDF files and convert them to images
|
| 13 |
def process_pdfs(pdf_files):
|
|
@@ -130,7 +131,6 @@ def main_process(files, tanggal_berangkat, tanggal_pulang):
|
|
| 130 |
file_path = file.name if hasattr(file, 'name') else file
|
| 131 |
|
| 132 |
if file_path.lower().endswith('.zip'):
|
| 133 |
-
# Extract zip and process contained files
|
| 134 |
extracted_files = extract_zip_and_collect_files(file_path)
|
| 135 |
for extracted_file in extracted_files:
|
| 136 |
if extracted_file.lower().endswith('.pdf'):
|
|
@@ -149,7 +149,17 @@ def main_process(files, tanggal_berangkat, tanggal_pulang):
|
|
| 149 |
raise ValueError(f"File {file_path} is not a valid image, PDF, or ZIP.")
|
| 150 |
|
| 151 |
summary = gemini_analysis(all_images, tanggal_berangkat, tanggal_pulang)
|
| 152 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 153 |
|
| 154 |
|
| 155 |
# Gradio UI update: add ".zip" to accepted file types
|
|
@@ -173,9 +183,13 @@ with gr.Blocks() as demo:
|
|
| 173 |
placeholder="Masukan Tanggal Kepulangan",
|
| 174 |
type="text"
|
| 175 |
)
|
| 176 |
-
|
| 177 |
-
|
|
|
|
| 178 |
|
| 179 |
-
|
| 180 |
|
|
|
|
|
|
|
|
|
|
| 181 |
demo.launch()
|
|
|
|
| 8 |
import tempfile
|
| 9 |
os.system("apt-get install poppler-utils")
|
| 10 |
import datetime
|
| 11 |
+
from docx import Document
|
| 12 |
|
| 13 |
# Function to process a list of PDF files and convert them to images
|
| 14 |
def process_pdfs(pdf_files):
|
|
|
|
| 131 |
file_path = file.name if hasattr(file, 'name') else file
|
| 132 |
|
| 133 |
if file_path.lower().endswith('.zip'):
|
|
|
|
| 134 |
extracted_files = extract_zip_and_collect_files(file_path)
|
| 135 |
for extracted_file in extracted_files:
|
| 136 |
if extracted_file.lower().endswith('.pdf'):
|
|
|
|
| 149 |
raise ValueError(f"File {file_path} is not a valid image, PDF, or ZIP.")
|
| 150 |
|
| 151 |
summary = gemini_analysis(all_images, tanggal_berangkat, tanggal_pulang)
|
| 152 |
+
|
| 153 |
+
# Save to DOCX
|
| 154 |
+
doc = Document()
|
| 155 |
+
doc.add_heading("Visa Document Check Summary", level=1)
|
| 156 |
+
for line in summary.split("\n"):
|
| 157 |
+
doc.add_paragraph(line)
|
| 158 |
+
|
| 159 |
+
temp_docx_path = os.path.join(tempfile.gettempdir(), f"summary_{datetime.datetime.now().strftime('%Y%m%d%H%M%S')}.docx")
|
| 160 |
+
doc.save(temp_docx_path)
|
| 161 |
+
|
| 162 |
+
return summary, temp_docx_path
|
| 163 |
|
| 164 |
|
| 165 |
# Gradio UI update: add ".zip" to accepted file types
|
|
|
|
| 183 |
placeholder="Masukan Tanggal Kepulangan",
|
| 184 |
type="text"
|
| 185 |
)
|
| 186 |
+
with gr.Row():
|
| 187 |
+
run_btn = gr.Button("π Run Analysis")
|
| 188 |
+
download_output = gr.File(label="π₯ Download Summary as DOCX", visible=True)
|
| 189 |
|
| 190 |
+
output = gr.Textbox(label="π Summary Result", lines=20)
|
| 191 |
|
| 192 |
+
run_btn.click(fn=main_process,
|
| 193 |
+
inputs=[file_input, tanggal_berangkat, tanggal_pulang],
|
| 194 |
+
outputs=[output, download_output])
|
| 195 |
demo.launch()
|