iamrobotbear commited on
Commit
834d05a
·
1 Parent(s): 28b27db

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -12
app.py CHANGED
@@ -1,5 +1,4 @@
1
  import gradio as gr
2
- from gradio import inputs, outputs # Import inputs and outputs from gradio
3
  import torch
4
  from PIL import Image
5
  import pandas as pd
@@ -9,12 +8,8 @@ from transformers import AutoTokenizer, AutoModelForCausalLM, AutoProcessor
9
  import tensorflow as tf
10
  import tensorflow_hub as hub
11
  import io
12
- import tempfile
13
  from sklearn.metrics.pairwise import cosine_similarity
14
-
15
-
16
-
17
- # Import logging module
18
  import logging
19
 
20
  # Configure logging
@@ -85,7 +80,7 @@ def generate_caption(processor, model, image):
85
  logging.info('Finished generate_caption')
86
  return generated_caption
87
 
88
-
89
  def save_dataframe_to_csv(df):
90
  csv_buffer = io.StringIO()
91
  df.to_csv(csv_buffer, index=False)
@@ -134,10 +129,8 @@ def process_images_and_statements(image):
134
  'Final Combined Score': f"{final_score:.2f}%" # Format as percentage with two decimal places
135
  }, ignore_index=True)
136
 
137
- logging.info
138
  logging.info('Finished process_images_and_statements')
139
 
140
- # Return the DataFrame directly as output (no need to convert to HTML)
141
  # Save results_df to a CSV file
142
  csv_results = save_dataframe_to_csv(results_df)
143
 
@@ -152,10 +145,10 @@ output_csv = gr.outputs.File(label="Download CSV")
152
  iface = gr.Interface(
153
  fn=process_images_and_statements,
154
  inputs=image_input,
155
- outputs=[output_df, output_csv],
156
  title="Image Captioning and Image-Text Matching",
157
  theme='sudeepshouche/minimalist',
158
- css=".output { flex-direction: column; } .output .outputs { width: 100%; }"
159
  )
160
 
161
- iface.launch()
 
1
  import gradio as gr
 
2
  import torch
3
  from PIL import Image
4
  import pandas as pd
 
8
  import tensorflow as tf
9
  import tensorflow_hub as hub
10
  import io
 
11
  from sklearn.metrics.pairwise import cosine_similarity
12
+ import tempfile # Add this import
 
 
 
13
  import logging
14
 
15
  # Configure logging
 
80
  logging.info('Finished generate_caption')
81
  return generated_caption
82
 
83
+ # Function to save dataframe results to a CSV string for download
84
  def save_dataframe_to_csv(df):
85
  csv_buffer = io.StringIO()
86
  df.to_csv(csv_buffer, index=False)
 
129
  'Final Combined Score': f"{final_score:.2f}%" # Format as percentage with two decimal places
130
  }, ignore_index=True)
131
 
 
132
  logging.info('Finished process_images_and_statements')
133
 
 
134
  # Save results_df to a CSV file
135
  csv_results = save_dataframe_to_csv(results_df)
136
 
 
145
  iface = gr.Interface(
146
  fn=process_images_and_statements,
147
  inputs=image_input,
148
+ outputs=[output_df, output_csv], # Include both the DataFrame and CSV file outputs
149
  title="Image Captioning and Image-Text Matching",
150
  theme='sudeepshouche/minimalist',
151
+ css=".output { flex-direction: column; } .output .outputs { width: 100%; }" # Custom CSS
152
  )
153
 
154
+ iface.launch()