Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -140,7 +140,7 @@ Berikut kami informasikan kekurangan dokumen yang *WAJIB* dibawa saat biometric
|
|
| 140 |
)
|
| 141 |
analysis = response_1.text
|
| 142 |
# Perform valid list generation
|
| 143 |
-
prompt_2 = "Dari analisa diatas, Rangkum menjadi list/daftar dokumen
|
| 144 |
response_2 = client.models.generate_content(
|
| 145 |
model="gemini-2.0-flash-lite",
|
| 146 |
contents=[analysis, prompt_2], # Pass prompt and image files
|
|
@@ -163,8 +163,7 @@ Berikut kami informasikan kekurangan dokumen yang *WAJIB* dibawa saat biometric
|
|
| 163 |
return analysis, docs_list
|
| 164 |
|
| 165 |
|
| 166 |
-
def
|
| 167 |
-
|
| 168 |
# Inisialisasi Gemini client
|
| 169 |
client = genai.Client(api_key=api_key)
|
| 170 |
|
|
@@ -178,7 +177,6 @@ Jangan tambahkan penjelasan, tanda kutip, titik, atau teks tambahan lainnya.
|
|
| 178 |
Contoh:
|
| 179 |
Gambar : [tampak gambar KTP]
|
| 180 |
Output: KTP
|
| 181 |
-
|
| 182 |
Gambar: [gambar sebenarnya]
|
| 183 |
Output:
|
| 184 |
'''
|
|
@@ -197,19 +195,13 @@ Output:
|
|
| 197 |
filename = response.text.strip().lower()
|
| 198 |
renamed_images.append({"image": image, "filename": filename})
|
| 199 |
|
| 200 |
-
# Step 2:
|
| 201 |
-
filtered_images = [
|
| 202 |
-
item for item in renamed_images
|
| 203 |
-
if os.path.splitext(item["filename"])[0] in [v.lower() for v in docs_list]
|
| 204 |
-
]
|
| 205 |
-
|
| 206 |
-
# Step 3: Kelompokkan berdasarkan nama file (tanpa .jpg)
|
| 207 |
grouped = {}
|
| 208 |
-
for item in
|
| 209 |
name = os.path.splitext(item["filename"])[0]
|
| 210 |
grouped.setdefault(name, []).append(item["image"])
|
| 211 |
|
| 212 |
-
# Step
|
| 213 |
temp_dir = tempfile.mkdtemp()
|
| 214 |
zip_path = os.path.join(tempfile.gettempdir(), zip_name)
|
| 215 |
|
|
@@ -271,7 +263,7 @@ def main_process(files, tanggal_berangkat, tanggal_pulang, api_key):
|
|
| 271 |
doc.save(temp_docx_path)
|
| 272 |
|
| 273 |
# Filtering the file
|
| 274 |
-
zip_file_path = process_and_zip_valid_images(all_images,
|
| 275 |
return temp_docx_path, valid_list, zip_file_path
|
| 276 |
|
| 277 |
|
|
|
|
| 140 |
)
|
| 141 |
analysis = response_1.text
|
| 142 |
# Perform valid list generation
|
| 143 |
+
prompt_2 = "Dari analisa diatas, Rangkum menjadi list/daftar dokumen YANG TIDAK VALID SAJA. Misal: 'paspor', 'pasfoto', 'kartukeluarga', 'buktinikah', 'KTP', 'suratkelahiran', 'suratsponsor', 'suratkerja', 'NIB', 'SIUP', 'suratjaminanstaff', 'suratsekolah', 'kontrakkerja', 'suratpensiun', 'rekeningkoran', 'slipgaji'. Jangan tambahkan kata-kata atau kalimat lain. Tidak boleh ada file di luar contoh."
|
| 144 |
response_2 = client.models.generate_content(
|
| 145 |
model="gemini-2.0-flash-lite",
|
| 146 |
contents=[analysis, prompt_2], # Pass prompt and image files
|
|
|
|
| 163 |
return analysis, docs_list
|
| 164 |
|
| 165 |
|
| 166 |
+
def process_and_zip_all_images(images, api_key, zip_name="Valid_Docs.zip"):
|
|
|
|
| 167 |
# Inisialisasi Gemini client
|
| 168 |
client = genai.Client(api_key=api_key)
|
| 169 |
|
|
|
|
| 177 |
Contoh:
|
| 178 |
Gambar : [tampak gambar KTP]
|
| 179 |
Output: KTP
|
|
|
|
| 180 |
Gambar: [gambar sebenarnya]
|
| 181 |
Output:
|
| 182 |
'''
|
|
|
|
| 195 |
filename = response.text.strip().lower()
|
| 196 |
renamed_images.append({"image": image, "filename": filename})
|
| 197 |
|
| 198 |
+
# Step 2: Kelompokkan berdasarkan nama file (tanpa ekstensi)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 199 |
grouped = {}
|
| 200 |
+
for item in renamed_images:
|
| 201 |
name = os.path.splitext(item["filename"])[0]
|
| 202 |
grouped.setdefault(name, []).append(item["image"])
|
| 203 |
|
| 204 |
+
# Step 3: Simpan ke PDF dan masukkan ke ZIP
|
| 205 |
temp_dir = tempfile.mkdtemp()
|
| 206 |
zip_path = os.path.join(tempfile.gettempdir(), zip_name)
|
| 207 |
|
|
|
|
| 263 |
doc.save(temp_docx_path)
|
| 264 |
|
| 265 |
# Filtering the file
|
| 266 |
+
zip_file_path = process_and_zip_valid_images(all_images, api_key, zip_name=f'Valid_ZIP_{base_name}.zip')
|
| 267 |
return temp_docx_path, valid_list, zip_file_path
|
| 268 |
|
| 269 |
|