iamrobotbear commited on
Commit
8b69d1b
·
1 Parent(s): 26c12e7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -9
app.py CHANGED
@@ -73,8 +73,11 @@ def save_dataframe_to_csv(df):
73
  return temp_file_path
74
 
75
  # Main function to perform image captioning and image-text matching
76
- def process_images_and_statements(image, filename):
77
  logging.info('Starting process_images_and_statements')
 
 
 
78
 
79
  # Generate image caption for the uploaded image using git-large-r-textcaps
80
  caption = generate_caption(git_processor_large_textcaps, git_model_large_textcaps, image)
@@ -119,19 +122,14 @@ def process_images_and_statements(image, filename):
119
  # Return both the DataFrame and the CSV data for the Gradio interface
120
  return results_df, csv_results # <--- Return results_df and csv_results
121
 
122
- # Define a function to handle the user's input
123
- def handle_input(image, filename):
124
- # Call the process_images_and_statements function with the image and filename
125
- return process_images_and_statements(image, filename.name)
126
  # Gradio interface
127
- image_input = gr.inputs.Image()
128
- file_input = gr.inputs.File() # Add an input element to allow users to provide the image filename
129
  output_df = gr.outputs.Dataframe(type="pandas", label="Results")
130
  output_csv = gr.outputs.File(label="Download CSV")
131
 
132
  iface = gr.Interface(
133
- fn=handle_input, # Use the handle_input function to handle user input
134
- inputs=[image_input, file_input], # Include both the image and filename inputs
135
  outputs=[output_df, output_csv],
136
  title="Image Captioning and Image-Text Matching",
137
  theme='sudeepshouche/minimalist',
 
73
  return temp_file_path
74
 
75
  # Main function to perform image captioning and image-text matching
76
+ def process_images_and_statements(image, file):
77
  logging.info('Starting process_images_and_statements')
78
+
79
+ # Extract the filename from the file object
80
+ filename = file.name
81
 
82
  # Generate image caption for the uploaded image using git-large-r-textcaps
83
  caption = generate_caption(git_processor_large_textcaps, git_model_large_textcaps, image)
 
122
  # Return both the DataFrame and the CSV data for the Gradio interface
123
  return results_df, csv_results # <--- Return results_df and csv_results
124
 
 
 
 
 
125
  # Gradio interface
126
+ image_input = gr.inputs.Image() # Create default image input element
 
127
  output_df = gr.outputs.Dataframe(type="pandas", label="Results")
128
  output_csv = gr.outputs.File(label="Download CSV")
129
 
130
  iface = gr.Interface(
131
+ fn=process_images_and_statements,
132
+ inputs=image_input,
133
  outputs=[output_df, output_csv],
134
  title="Image Captioning and Image-Text Matching",
135
  theme='sudeepshouche/minimalist',