Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -193,22 +193,13 @@ def gradio_predict(video,image, question):
|
|
| 193 |
return answer
|
| 194 |
|
| 195 |
|
| 196 |
-
# def convert_and_save(data):
|
| 197 |
-
# # Convert the answer dictionary to a DataFrame
|
| 198 |
-
# df = pd.DataFrame([data])
|
| 199 |
-
# # Convert DataFrame to CSV format
|
| 200 |
-
# csv_buffer = StringIO()
|
| 201 |
-
# df.to_csv(csv_buffer, index=False)
|
| 202 |
-
# # Gradio file components expect (filename, filecontents), hence the StringIO contents are read
|
| 203 |
-
# return ("annotations.csv", csv_buffer.getvalue())
|
| 204 |
-
|
| 205 |
def convert_and_save(data):
|
| 206 |
-
# Assuming 'data' is a dictionary
|
| 207 |
df = pd.DataFrame([data])
|
| 208 |
-
|
| 209 |
-
|
| 210 |
-
#
|
| 211 |
-
return ("annotations.csv",
|
| 212 |
|
| 213 |
css = """
|
| 214 |
#container{
|
|
@@ -244,12 +235,16 @@ with gr.Blocks(css = css) as app:
|
|
| 244 |
with gr.Column():
|
| 245 |
answer = gr.TextArea(label="Answer")
|
| 246 |
save_btn = gr.Button("Save as CSV")
|
|
|
|
|
|
|
|
|
|
| 247 |
|
| 248 |
|
| 249 |
btn.click(gradio_predict, inputs=[video,image, question], outputs=answer)
|
| 250 |
|
| 251 |
# Button to save the answer as CSV
|
| 252 |
-
save_btn.click(convert_and_save, inputs=answer, outputs=
|
|
|
|
| 253 |
|
| 254 |
gr.Examples(
|
| 255 |
examples=test_examples,
|
|
|
|
| 193 |
return answer
|
| 194 |
|
| 195 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 196 |
def convert_and_save(data):
|
| 197 |
+
# Assuming 'data' is a dictionary to convert into a DataFrame and save as CSV
|
| 198 |
df = pd.DataFrame([data])
|
| 199 |
+
csv_buffer = StringIO()
|
| 200 |
+
df.to_csv(csv_buffer, index=False)
|
| 201 |
+
csv_buffer.seek(0) # Move to the start of the StringIO buffer
|
| 202 |
+
return ("annotations.csv", csv_buffer.getvalue())
|
| 203 |
|
| 204 |
css = """
|
| 205 |
#container{
|
|
|
|
| 235 |
with gr.Column():
|
| 236 |
answer = gr.TextArea(label="Answer")
|
| 237 |
save_btn = gr.Button("Save as CSV")
|
| 238 |
+
download_link = gr.File(label="Download CSV")
|
| 239 |
+
|
| 240 |
+
# Make sure the inputs and outputs match in your click function
|
| 241 |
|
| 242 |
|
| 243 |
btn.click(gradio_predict, inputs=[video,image, question], outputs=answer)
|
| 244 |
|
| 245 |
# Button to save the answer as CSV
|
| 246 |
+
save_btn.click(fn=convert_and_save, inputs=answer, outputs=download_link)
|
| 247 |
+
|
| 248 |
|
| 249 |
gr.Examples(
|
| 250 |
examples=test_examples,
|