iamrobotbear commited on
Commit
2a7a772
·
1 Parent(s): ab23201

surely is broken

Browse files
Files changed (1) hide show
  1. app.py +10 -9
app.py CHANGED
@@ -51,6 +51,7 @@ def compute_itm_score(image, statement):
51
  score = itm_scores[:, 1].item()
52
  logging.info('Finished compute_itm_score')
53
  return score
 
54
  def generate_caption(processor, model, image):
55
  logging.info('Starting generate_caption')
56
  inputs = processor(images=image, return_tensors="pt").to(device)
@@ -72,18 +73,18 @@ def save_dataframe_to_csv(df):
72
  # Return the file path (no need to reopen the file with "rb" mode)
73
  return temp_file_path
74
 
75
-
76
- # Define a validation function to check if the uploaded file is an image
77
- def validate_image_file(file):
78
  allowed_extensions = [".jpg", ".jpeg", ".png", ".gif", ".bmp", ".tiff"]
79
  file_extension = os.path.splitext(file.name)[1]
80
- if file_extension.lower() not in allowed_extensions:
81
- return "Invalid file type. Please upload an image file (e.g., .jpg, .png, .jpeg)."
82
- return None
83
 
84
  # Main function to perform image captioning and image-text matching
85
  def process_images_and_statements(file):
86
- logging.info('Starting process_images_and_statements')
 
 
87
 
88
  # Extract the filename from the file object
89
  filename = file.name
@@ -135,7 +136,7 @@ def process_images_and_statements(file):
135
  return results_df, csv_results # <--- Return results_df and csv_results
136
 
137
  # Gradio interface
138
- file_input = gr.inputs.File(label="Upload Image", validate=validate_image_file) # Use File input for image upload
139
  output_df = gr.outputs.Dataframe(type="pandas", label="Results")
140
  output_csv = gr.outputs.File(label="Download CSV")
141
 
@@ -149,4 +150,4 @@ iface = gr.Interface(
149
  )
150
 
151
  # Launch the Gradio interface
152
- iface.launch()
 
51
  score = itm_scores[:, 1].item()
52
  logging.info('Finished compute_itm_score')
53
  return score
54
+
55
  def generate_caption(processor, model, image):
56
  logging.info('Starting generate_caption')
57
  inputs = processor(images=image, return_tensors="pt").to(device)
 
73
  # Return the file path (no need to reopen the file with "rb" mode)
74
  return temp_file_path
75
 
76
+ # Define a function to check if the uploaded file is an image
77
+ def is_image_file(file):
 
78
  allowed_extensions = [".jpg", ".jpeg", ".png", ".gif", ".bmp", ".tiff"]
79
  file_extension = os.path.splitext(file.name)[1]
80
+ return file_extension.lower() in allowed_extensions
81
+
 
82
 
83
  # Main function to perform image captioning and image-text matching
84
  def process_images_and_statements(file):
85
+ # Check if the uploaded file is an image
86
+ if not is_image_file(file):
87
+ return "Invalid file type. Please upload an image file (e.g., .jpg, .png, .jpeg)."
88
 
89
  # Extract the filename from the file object
90
  filename = file.name
 
136
  return results_df, csv_results # <--- Return results_df and csv_results
137
 
138
  # Gradio interface
139
+ file_input = gr.inputs.File(label="Upload Image") # Use File input for image upload
140
  output_df = gr.outputs.Dataframe(type="pandas", label="Results")
141
  output_csv = gr.outputs.File(label="Download CSV")
142
 
 
150
  )
151
 
152
  # Launch the Gradio interface
153
+ iface.launch()