Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -144,10 +144,7 @@ def gemini_analysis(images, tanggal_berangkat, tanggal_pulang, api_key):
|
|
| 144 |
response_mime_type="application/json"
|
| 145 |
)
|
| 146 |
)
|
| 147 |
-
|
| 148 |
-
model="gemini-2.0-flash-lite", contents=[prompt_with_date] + images)
|
| 149 |
-
total_tokens = token_counter.total_tokens
|
| 150 |
-
total_tokens_in_idr = total_tokens*5/1000
|
| 151 |
raw_output = response.text
|
| 152 |
# β
Inisialisasi variabel default
|
| 153 |
analysis = {}
|
|
@@ -172,7 +169,7 @@ Halo Kak selamat malam π
|
|
| 172 |
form_filling_str = json.dumps(form_filling, indent=2, ensure_ascii=False)
|
| 173 |
except Exception as e:
|
| 174 |
print(f"Error parsing JSON: {e}")
|
| 175 |
-
return raw_output, analysis_str, summary, invalid_list_str, notice_msg, form_filling_str,
|
| 176 |
|
| 177 |
def process_and_zip_all_images(images, api_key, zip_name="All_PDF_Docs.zip"):
|
| 178 |
# Inisialisasi Gemini client
|
|
@@ -253,7 +250,7 @@ def main_process(files, tanggal_berangkat, tanggal_pulang, api_key, dpi):
|
|
| 253 |
raise ValueError(f"File {file_path} is not a valid image, PDF, or ZIP.")
|
| 254 |
|
| 255 |
# Generate summary from images
|
| 256 |
-
raw_output, analysis_str, summary, invalid_list_str, notice_msg, form_filling_str,
|
| 257 |
rdf = random.randint(5, 10)
|
| 258 |
time.sleep(rdf)
|
| 259 |
|
|
@@ -277,7 +274,7 @@ def main_process(files, tanggal_berangkat, tanggal_pulang, api_key, dpi):
|
|
| 277 |
|
| 278 |
# Filtering the file
|
| 279 |
zip_file_path = process_and_zip_all_images(all_images, api_key, zip_name=f'All_PDF_Docs_{base_name}.zip')
|
| 280 |
-
return temp_docx_path, form_filling_str, zip_file_path, invalid_list_str, raw_output, summary, notice_msg,
|
| 281 |
|
| 282 |
|
| 283 |
# Gradio UI update: add ".zip" to accepted file types
|
|
@@ -333,12 +330,12 @@ with gr.Blocks() as demo:
|
|
| 333 |
gr.Markdown("## π RAW OUTPUT FROM AI")
|
| 334 |
raw_output = gr.Textbox(label="π RAW OUTPUT", lines=20)
|
| 335 |
gr.Markdown("Token cost in IDR")
|
| 336 |
-
|
| 337 |
|
| 338 |
run_btn.click(
|
| 339 |
fn=main_process,
|
| 340 |
inputs=[file_input, tanggal_berangkat, tanggal_pulang, api_key, dpi_slider],
|
| 341 |
-
outputs=[download_output_docx, form_filling_output, download_valid_zip, invalid_list_output, raw_output, summary_output, notice_msg,
|
| 342 |
)
|
| 343 |
|
| 344 |
demo.launch(debug=True)
|
|
|
|
| 144 |
response_mime_type="application/json"
|
| 145 |
)
|
| 146 |
)
|
| 147 |
+
token_usage = response.usage_metadata
|
|
|
|
|
|
|
|
|
|
| 148 |
raw_output = response.text
|
| 149 |
# β
Inisialisasi variabel default
|
| 150 |
analysis = {}
|
|
|
|
| 169 |
form_filling_str = json.dumps(form_filling, indent=2, ensure_ascii=False)
|
| 170 |
except Exception as e:
|
| 171 |
print(f"Error parsing JSON: {e}")
|
| 172 |
+
return raw_output, analysis_str, summary, invalid_list_str, notice_msg, form_filling_str, token_usage
|
| 173 |
|
| 174 |
def process_and_zip_all_images(images, api_key, zip_name="All_PDF_Docs.zip"):
|
| 175 |
# Inisialisasi Gemini client
|
|
|
|
| 250 |
raise ValueError(f"File {file_path} is not a valid image, PDF, or ZIP.")
|
| 251 |
|
| 252 |
# Generate summary from images
|
| 253 |
+
raw_output, analysis_str, summary, invalid_list_str, notice_msg, form_filling_str, token_usage = gemini_analysis(all_images, tanggal_berangkat, tanggal_pulang, api_key)
|
| 254 |
rdf = random.randint(5, 10)
|
| 255 |
time.sleep(rdf)
|
| 256 |
|
|
|
|
| 274 |
|
| 275 |
# Filtering the file
|
| 276 |
zip_file_path = process_and_zip_all_images(all_images, api_key, zip_name=f'All_PDF_Docs_{base_name}.zip')
|
| 277 |
+
return temp_docx_path, form_filling_str, zip_file_path, invalid_list_str, raw_output, summary, notice_msg, token_usage
|
| 278 |
|
| 279 |
|
| 280 |
# Gradio UI update: add ".zip" to accepted file types
|
|
|
|
| 330 |
gr.Markdown("## π RAW OUTPUT FROM AI")
|
| 331 |
raw_output = gr.Textbox(label="π RAW OUTPUT", lines=20)
|
| 332 |
gr.Markdown("Token cost in IDR")
|
| 333 |
+
token_usage = gr.Textbox(label="Token cost in IDR", lines=5)
|
| 334 |
|
| 335 |
run_btn.click(
|
| 336 |
fn=main_process,
|
| 337 |
inputs=[file_input, tanggal_berangkat, tanggal_pulang, api_key, dpi_slider],
|
| 338 |
+
outputs=[download_output_docx, form_filling_output, download_valid_zip, invalid_list_output, raw_output, summary_output, notice_msg, token_usage]
|
| 339 |
)
|
| 340 |
|
| 341 |
demo.launch(debug=True)
|