Spaces:
Sleeping
Sleeping
removed api key input
Browse files
app.py
CHANGED
|
@@ -49,8 +49,8 @@ def process_pdfs(pdf_files, dpi):
|
|
| 49 |
|
| 50 |
|
| 51 |
# Function to analyze the extracted image using Google GenAI
|
| 52 |
-
def gemini_analysis(images, tanggal_berangkat, tanggal_pulang
|
| 53 |
-
client = genai.Client(api_key=
|
| 54 |
# Define your prompt
|
| 55 |
prompt = '''Anda bertugas memvalidasi kelengkapan, kesesuaian dan konsistensi data dari dokumen individual berdasarkan syarat Visa di bawah. Cukup fokus pada syarat yang diberikan tanpa mengambil referensi lain.
|
| 56 |
Pastikan data seperti nama, tanggal, tujuan dan lainnya konsisten antar dokumen.
|
|
@@ -172,9 +172,9 @@ Halo Kak selamat malam 😊
|
|
| 172 |
print(f"Error parsing JSON: {e}")
|
| 173 |
return raw_output, analysis_str, summary, invalid_list_str, notice_msg, form_filling_str, token_usage
|
| 174 |
|
| 175 |
-
def process_and_zip_all_images(images,
|
| 176 |
# Inisialisasi Gemini client
|
| 177 |
-
client = genai.Client(api_key=
|
| 178 |
|
| 179 |
# Prompt untuk klasifikasi nama file
|
| 180 |
prompt_3 = '''Anda adalah asisten yang membantu menamai file gambar dokumen.
|
|
@@ -225,7 +225,7 @@ Output:
|
|
| 225 |
zipf.write(pdf_path, arcname=f"{doc_name}.pdf")
|
| 226 |
return zip_path
|
| 227 |
|
| 228 |
-
def main_process(files, tanggal_berangkat, tanggal_pulang,
|
| 229 |
all_images = []
|
| 230 |
image_paths_for_zip = []
|
| 231 |
|
|
@@ -251,7 +251,7 @@ def main_process(files, tanggal_berangkat, tanggal_pulang, api_key, dpi):
|
|
| 251 |
raise ValueError(f"File {file_path} is not a valid image, PDF, or ZIP.")
|
| 252 |
|
| 253 |
# Generate summary from images
|
| 254 |
-
raw_output, analysis_str, summary, invalid_list_str, notice_msg, form_filling_str, token_usage = gemini_analysis(all_images, tanggal_berangkat, tanggal_pulang
|
| 255 |
rdf = random.randint(5, 10)
|
| 256 |
time.sleep(rdf)
|
| 257 |
|
|
@@ -274,7 +274,7 @@ def main_process(files, tanggal_berangkat, tanggal_pulang, api_key, dpi):
|
|
| 274 |
doc.save(temp_docx_path)
|
| 275 |
|
| 276 |
# Filtering the file
|
| 277 |
-
zip_file_path = process_and_zip_all_images(all_images,
|
| 278 |
return temp_docx_path, form_filling_str, zip_file_path, invalid_list_str, raw_output, summary, notice_msg, token_usage
|
| 279 |
|
| 280 |
|
|
@@ -300,11 +300,11 @@ with gr.Blocks() as demo:
|
|
| 300 |
placeholder="Masukan Tanggal Kepulangan",
|
| 301 |
type="text"
|
| 302 |
)
|
| 303 |
-
api_key = gr.Textbox(
|
| 304 |
-
|
| 305 |
-
|
| 306 |
-
|
| 307 |
-
)
|
| 308 |
dpi_slider = gr.Slider(
|
| 309 |
minimum=100,
|
| 310 |
maximum=400,
|
|
@@ -335,7 +335,7 @@ with gr.Blocks() as demo:
|
|
| 335 |
|
| 336 |
run_btn.click(
|
| 337 |
fn=main_process,
|
| 338 |
-
inputs=[file_input, tanggal_berangkat, tanggal_pulang,
|
| 339 |
outputs=[download_output_docx, form_filling_output, download_valid_zip, invalid_list_output, raw_output, summary_output, notice_msg, token_usage]
|
| 340 |
)
|
| 341 |
|
|
|
|
| 49 |
|
| 50 |
|
| 51 |
# Function to analyze the extracted image using Google GenAI
|
| 52 |
+
def gemini_analysis(images, tanggal_berangkat, tanggal_pulang):
|
| 53 |
+
client = genai.Client(api_key='AIzaSyBpviFHkaEF-GAjMMl28dIS1poikhBqq_w')
|
| 54 |
# Define your prompt
|
| 55 |
prompt = '''Anda bertugas memvalidasi kelengkapan, kesesuaian dan konsistensi data dari dokumen individual berdasarkan syarat Visa di bawah. Cukup fokus pada syarat yang diberikan tanpa mengambil referensi lain.
|
| 56 |
Pastikan data seperti nama, tanggal, tujuan dan lainnya konsisten antar dokumen.
|
|
|
|
| 172 |
print(f"Error parsing JSON: {e}")
|
| 173 |
return raw_output, analysis_str, summary, invalid_list_str, notice_msg, form_filling_str, token_usage
|
| 174 |
|
| 175 |
+
def process_and_zip_all_images(images, zip_name="All_PDF_Docs.zip"):
|
| 176 |
# Inisialisasi Gemini client
|
| 177 |
+
client = genai.Client(api_key='AIzaSyBpviFHkaEF-GAjMMl28dIS1poikhBqq_w')
|
| 178 |
|
| 179 |
# Prompt untuk klasifikasi nama file
|
| 180 |
prompt_3 = '''Anda adalah asisten yang membantu menamai file gambar dokumen.
|
|
|
|
| 225 |
zipf.write(pdf_path, arcname=f"{doc_name}.pdf")
|
| 226 |
return zip_path
|
| 227 |
|
| 228 |
+
def main_process(files, tanggal_berangkat, tanggal_pulang, dpi):
|
| 229 |
all_images = []
|
| 230 |
image_paths_for_zip = []
|
| 231 |
|
|
|
|
| 251 |
raise ValueError(f"File {file_path} is not a valid image, PDF, or ZIP.")
|
| 252 |
|
| 253 |
# Generate summary from images
|
| 254 |
+
raw_output, analysis_str, summary, invalid_list_str, notice_msg, form_filling_str, token_usage = gemini_analysis(all_images, tanggal_berangkat, tanggal_pulang)
|
| 255 |
rdf = random.randint(5, 10)
|
| 256 |
time.sleep(rdf)
|
| 257 |
|
|
|
|
| 274 |
doc.save(temp_docx_path)
|
| 275 |
|
| 276 |
# Filtering the file
|
| 277 |
+
zip_file_path = process_and_zip_all_images(all_images, zip_name=f'All_PDF_Docs_{base_name}.zip')
|
| 278 |
return temp_docx_path, form_filling_str, zip_file_path, invalid_list_str, raw_output, summary, notice_msg, token_usage
|
| 279 |
|
| 280 |
|
|
|
|
| 300 |
placeholder="Masukan Tanggal Kepulangan",
|
| 301 |
type="text"
|
| 302 |
)
|
| 303 |
+
# api_key = gr.Textbox(
|
| 304 |
+
# label="Gemini API Key",
|
| 305 |
+
# placeholder="Masukan Kode API",
|
| 306 |
+
# type="text"
|
| 307 |
+
# )
|
| 308 |
dpi_slider = gr.Slider(
|
| 309 |
minimum=100,
|
| 310 |
maximum=400,
|
|
|
|
| 335 |
|
| 336 |
run_btn.click(
|
| 337 |
fn=main_process,
|
| 338 |
+
inputs=[file_input, tanggal_berangkat, tanggal_pulang, dpi_slider],
|
| 339 |
outputs=[download_output_docx, form_filling_output, download_valid_zip, invalid_list_output, raw_output, summary_output, notice_msg, token_usage]
|
| 340 |
)
|
| 341 |
|