mkaramb commited on
Commit
5301308
·
verified ·
1 Parent(s): e4387b3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -1
app.py CHANGED
@@ -71,6 +71,7 @@ def unzip_and_find_jpgs(file_path):
71
  return jpg_files
72
 
73
  def process_images(uploaded_file):
 
74
  global results_df
75
  results_df = results_df.iloc[0:0] # Clear the DataFrame
76
  file_path = uploaded_file.name # Gradio provides the file path
@@ -80,9 +81,11 @@ def process_images(uploaded_file):
80
  image_files = unzip_and_find_jpgs(file_path)
81
 
82
  if not image_files:
 
83
  return "No JPG files found in the zip."
84
 
85
  for file_path in image_files:
 
86
  extracted_text, translated_text = batch_process_documents(file_path, "image/jpeg")
87
  new_row = pd.DataFrame([{
88
  "Filename": os.path.basename(file_path),
@@ -90,6 +93,7 @@ def process_images(uploaded_file):
90
  "Translated Text": translated_text
91
  }])
92
  results_df = pd.concat([results_df, new_row], ignore_index=True)
 
93
  except Exception as e:
94
  logging.error(f"An error occurred: {str(e)}")
95
  return f"An error occurred: {str(e)}"
@@ -99,7 +103,7 @@ def process_images(uploaded_file):
99
 
100
  interface = gr.Interface(
101
  fn=process_images,
102
- inputs="file",
103
  outputs="html",
104
  title="Document AI Translation",
105
  description="Upload a ZIP file containing JPEG/JPG images, and the system will extract and translate text from each image."
@@ -107,3 +111,4 @@ interface = gr.Interface(
107
 
108
  if __name__ == "__main__":
109
  interface.launch(debug=True)
 
 
71
  return jpg_files
72
 
73
  def process_images(uploaded_file):
74
+ logging.info("Started processing the uploaded file.") # Check if the function is triggered
75
  global results_df
76
  results_df = results_df.iloc[0:0] # Clear the DataFrame
77
  file_path = uploaded_file.name # Gradio provides the file path
 
81
  image_files = unzip_and_find_jpgs(file_path)
82
 
83
  if not image_files:
84
+ logging.warning("No JPG files found in the zip.")
85
  return "No JPG files found in the zip."
86
 
87
  for file_path in image_files:
88
+ logging.info(f"Processing image file {file_path}.")
89
  extracted_text, translated_text = batch_process_documents(file_path, "image/jpeg")
90
  new_row = pd.DataFrame([{
91
  "Filename": os.path.basename(file_path),
 
93
  "Translated Text": translated_text
94
  }])
95
  results_df = pd.concat([results_df, new_row], ignore_index=True)
96
+ logging.info(f"Data added for file {file_path}.")
97
  except Exception as e:
98
  logging.error(f"An error occurred: {str(e)}")
99
  return f"An error occurred: {str(e)}"
 
103
 
104
  interface = gr.Interface(
105
  fn=process_images,
106
+ inputs=gr.inputs.File(label="Upload ZIP File"),
107
  outputs="html",
108
  title="Document AI Translation",
109
  description="Upload a ZIP file containing JPEG/JPG images, and the system will extract and translate text from each image."
 
111
 
112
  if __name__ == "__main__":
113
  interface.launch(debug=True)
114
+