Spaces:
Paused
Paused
ManishThota
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -189,13 +189,18 @@ test_examples = [[None, "Images/cat_dog.jpeg", promt_cat_dog],
|
|
189 |
def gradio_predict(video,image, question):
|
190 |
answer = predict_answer(video,image, question)
|
191 |
|
192 |
-
|
193 |
-
df = pd.DataFrame([answer])
|
194 |
|
195 |
|
196 |
-
|
197 |
-
|
198 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
199 |
css = """
|
200 |
#container{
|
201 |
display: block;
|
@@ -229,11 +234,14 @@ with gr.Blocks(css = css) as app:
|
|
229 |
btn = gr.Button("Annotate")
|
230 |
with gr.Column():
|
231 |
answer = gr.TextArea(label="Answer")
|
232 |
-
|
233 |
|
234 |
|
235 |
btn.click(gradio_predict, inputs=[video,image, question], outputs=answer)
|
236 |
|
|
|
|
|
|
|
237 |
gr.Examples(
|
238 |
examples=test_examples,
|
239 |
inputs=[video,image, question],
|
|
|
189 |
def gradio_predict(video,image, question):
|
190 |
answer = predict_answer(video,image, question)
|
191 |
|
192 |
+
return answer
|
|
|
193 |
|
194 |
|
195 |
+
def convert_and_save(data):
|
196 |
+
# Convert the answer dictionary to a DataFrame
|
197 |
+
df = pd.DataFrame([data])
|
198 |
+
# Convert DataFrame to CSV format
|
199 |
+
csv_buffer = StringIO()
|
200 |
+
df.to_csv(csv_buffer, index=False)
|
201 |
+
# Gradio file components expect (filename, filecontents), hence the StringIO contents are read
|
202 |
+
return ("annotations.csv", csv_buffer.getvalue())
|
203 |
+
|
204 |
css = """
|
205 |
#container{
|
206 |
display: block;
|
|
|
234 |
btn = gr.Button("Annotate")
|
235 |
with gr.Column():
|
236 |
answer = gr.TextArea(label="Answer")
|
237 |
+
save_btn = gr.Button("Save as CSV")
|
238 |
|
239 |
|
240 |
btn.click(gradio_predict, inputs=[video,image, question], outputs=answer)
|
241 |
|
242 |
+
# Button to save the answer as CSV
|
243 |
+
save_btn.click(convert_and_save, inputs=answer, outputs=gr.File(label="Download CSV"))
|
244 |
+
|
245 |
gr.Examples(
|
246 |
examples=test_examples,
|
247 |
inputs=[video,image, question],
|