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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
from pdf2image import convert_from_path
|
| 3 |
+
from datetime import date
|
| 4 |
+
from PIL import Image
|
| 5 |
+
import gradio as gr
|
| 6 |
+
from google import genai
|
| 7 |
+
# Function to process a list of PDF files and convert them to images
|
| 8 |
+
def process_pdfs(pdf_files):
|
| 9 |
+
"""
|
| 10 |
+
Process a list of PDF files, convert each to images, and return all images.
|
| 11 |
+
"""
|
| 12 |
+
all_images = []
|
| 13 |
+
|
| 14 |
+
for pdf_file in pdf_files:
|
| 15 |
+
if not os.path.isfile(pdf_file):
|
| 16 |
+
raise ValueError(f"File {pdf_file} does not exist.")
|
| 17 |
+
|
| 18 |
+
images = convert_from_path(pdf_file, dpi=200) # Convert PDF pages to images
|
| 19 |
+
all_images.extend(images)
|
| 20 |
+
|
| 21 |
+
return all_images
|
| 22 |
+
|
| 23 |
+
# Function to analyze the extracted image using Google GenAI
|
| 24 |
+
def gemini_analysis(images):
|
| 25 |
+
"""
|
| 26 |
+
Analyze the extracted image using Google GenAI.
|
| 27 |
+
"""
|
| 28 |
+
# Initialize the GenAI client (make sure the API key is set properly)
|
| 29 |
+
today = date.today()
|
| 30 |
+
client = genai.Client(api_key=os.getenv("GOOGLE_API_KEY"))
|
| 31 |
+
# Define your prompt
|
| 32 |
+
prompt = f'''Anda bertugas memvalidasi kesesuaian dokumen individual berdasarkan syarat Visa di bawah. Cukup fokus pada syarat yang diberikan tanpa mengambil referensi lain.
|
| 33 |
+
Gunakan tanggal hari ini ({today}) sebagai tanggal pemeriksaan visa (bukan pengajuan).
|
| 34 |
+
---
|
| 35 |
+
|
| 36 |
+
DAFTAR SYARAT DOKUMEN YANG WAJIB DIPERIKSA:
|
| 37 |
+
|
| 38 |
+
1. Paspor
|
| 39 |
+
|
| 40 |
+
* Asli, aktif min. 6 bulan terhitung dari hari ini
|
| 41 |
+
* Ada tanda tangan pemilik
|
| 42 |
+
* Lampirkan paspor lama jika ada visa perjalanan sebelumnya
|
| 43 |
+
* Copy paspor sponsor jika disponsori
|
| 44 |
+
|
| 45 |
+
2. Fotokopi Paspor
|
| 46 |
+
|
| 47 |
+
* Halaman depan & tanda tangan
|
| 48 |
+
* Semua visa perjalanan sebelumnya jika ada (terutama 5 tahun terakhir)
|
| 49 |
+
|
| 50 |
+
3. Pas Foto
|
| 51 |
+
|
| 52 |
+
* Ukuran 3.5 x 4.5 cm, background putih
|
| 53 |
+
* Wajah terlihat 80%, alis tidak tertutup, tidak pakai softlens, tidak berbayang
|
| 54 |
+
|
| 55 |
+
4. Kartu Keluarga (KK)
|
| 56 |
+
|
| 57 |
+
* Minimal versi 2019 atau berbarcode
|
| 58 |
+
* Harus sesuai status (nikah/cerai/anak-anak β lampirkan dokumen pendukung)
|
| 59 |
+
* Harus ditranslate untuk VFS Germany
|
| 60 |
+
|
| 61 |
+
5. Akte Nikah
|
| 62 |
+
|
| 63 |
+
* Halaman biodata suami dan istri saja
|
| 64 |
+
* Jika istri ikut β wajib surat izin suami
|
| 65 |
+
|
| 66 |
+
6. KTP
|
| 67 |
+
|
| 68 |
+
* Nama harus sama dengan paspor
|
| 69 |
+
* Jika beda β lampirkan surat beda nama
|
| 70 |
+
|
| 71 |
+
7. Akte Lahir / Ijazah
|
| 72 |
+
|
| 73 |
+
* Wajib jika anak-anak atau peserta disponsori
|
| 74 |
+
|
| 75 |
+
8. Surat Sponsor (Guarantee Letter)
|
| 76 |
+
|
| 77 |
+
* Dalam Bahasa Inggris
|
| 78 |
+
* Tujuan negara, tanggal trip
|
| 79 |
+
* Siapa yang menanggung biaya
|
| 80 |
+
|
| 81 |
+
9. Status Pekerjaan
|
| 82 |
+
|
| 83 |
+
* Pegawai: Surat kerja + Slip gaji 3 bulan
|
| 84 |
+
* Pemilik usaha: NIB/SIUP + Surat jaminan staf
|
| 85 |
+
* Pelajar: Surat sekolah/universitas + kartu pelajar
|
| 86 |
+
* Freelancer/onlineshop: Kontrak kerja & 5 bukti transaksi
|
| 87 |
+
* Pensiun: Surat pensiun + guarantee dari keluarga
|
| 88 |
+
|
| 89 |
+
10. Rekening Koran (3 bulan)
|
| 90 |
+
|
| 91 |
+
* Atas nama pribadi & sponsor
|
| 92 |
+
* Cap & logo bank, nama, nomor rekening
|
| 93 |
+
* Saldo stabil min. Rp 35 juta/orang
|
| 94 |
+
|
| 95 |
+
11. Slip Gaji
|
| 96 |
+
|
| 97 |
+
* 3 bulan terakhir
|
| 98 |
+
* Jika suami lengkap β istri cukup lampirkan rekening koran suami
|
| 99 |
+
---
|
| 100 |
+
|
| 101 |
+
FORMAT JAWABAN UNTUK SETIAP DOKUMEN YANG DIUPLOAD:
|
| 102 |
+
|
| 103 |
+
- Jenis Dokumen : (jenis dokumen)
|
| 104 |
+
- Status : (Valid / Tidak Valid)
|
| 105 |
+
- Catatan : (Catatan singkat atau kekurangan isi dokumen)
|
| 106 |
+
'''
|
| 107 |
+
|
| 108 |
+
# Prepare the images for upload to Gemini (convert each image into bytes)
|
| 109 |
+
# Perform content generation using Google Gemini (images passed as files)
|
| 110 |
+
response = client.models.generate_content(
|
| 111 |
+
model="gemini-1.5-flash",
|
| 112 |
+
contents=[prompt] + images # Pass prompt and image files
|
| 113 |
+
)
|
| 114 |
+
return response.text
|
| 115 |
+
|
| 116 |
+
|
| 117 |
+
# full flow process
|
| 118 |
+
def main_process(files):
|
| 119 |
+
all_images = []
|
| 120 |
+
|
| 121 |
+
for file in files:
|
| 122 |
+
file_path = file.name if hasattr(file, 'name') else file # handle Gradio file objects
|
| 123 |
+
|
| 124 |
+
if file_path.lower().endswith('.pdf'):
|
| 125 |
+
images = process_pdfs([file_path]) # Pass as list
|
| 126 |
+
all_images.extend(images)
|
| 127 |
+
elif file_path.lower().endswith(('.jpg', '.jpeg', '.png')):
|
| 128 |
+
image = Image.open(file_path)
|
| 129 |
+
all_images.append(image)
|
| 130 |
+
else:
|
| 131 |
+
raise ValueError(f"File {file_path} is not a valid image or PDF.")
|
| 132 |
+
|
| 133 |
+
# Perform analysis using Gemini AI
|
| 134 |
+
summary = gemini_analysis(all_images)
|
| 135 |
+
return summary
|
| 136 |
+
|
| 137 |
+
|
| 138 |
+
# Gradio UI
|
| 139 |
+
with gr.Blocks() as demo:
|
| 140 |
+
gr.Markdown("## π§ Summarize Documents with Gemini AI (Image Analysis Only)")
|
| 141 |
+
with gr.Row():
|
| 142 |
+
file_input = gr.File(
|
| 143 |
+
label="Upload PDFs or Images (Multiple Supported)",
|
| 144 |
+
file_types=[".pdf", ".jpg", ".jpeg", ".png"],
|
| 145 |
+
file_count="multiple"
|
| 146 |
+
)
|
| 147 |
+
output = gr.Textbox(label="π Summary Result", lines=20)
|
| 148 |
+
run_btn = gr.Button("π Run Analysis")
|
| 149 |
+
run_btn.click(fn=main_process, inputs=[file_input], outputs=output)
|
| 150 |
+
|
| 151 |
+
demo.launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
pdf2image
|
| 2 |
+
Pillow
|
| 3 |
+
gradio
|
| 4 |
+
google-generativeai
|