ManishThota commited on
Commit
a21637d
1 Parent(s): 402c2c1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -18
app.py CHANGED
@@ -102,6 +102,7 @@ def analyze_videos(video_files, selected_questions):
102
  json_output = json.dumps(all_results, indent=4)
103
  return json_output, csv_content
104
 
 
105
  def download_csv(csv_content):
106
  """Creates a downloadable CSV file."""
107
  return gr.File.update(
@@ -109,25 +110,24 @@ def download_csv(csv_content):
109
  filename="video_analysis.csv",
110
  )
111
 
112
- # Define Gradio interface
113
- iface = gr.Interface(
114
- fn=analyze_videos,
115
- inputs=[
116
- gr.File(label="Upload Videos", file_count="multiple"),
117
- gr.CheckboxGroup(["hands_free", "standing/sitting", "interaction_with_background", "indoors/outdoors"],
118
- label="Select Questions to Apply")
119
- ],
120
- outputs=[
121
- gr.JSON(label="Analysis Results (JSON)"),
122
- gr.Textbox(label="CSV Results", lines=15),
123
- gr.Button("Download CSV")
124
- ],
125
- title="Video Analysis",
126
- description="Upload videos and select questions to analyze."
127
- )
128
 
129
- iface.download_button = iface.outputs[2] # Assign the third output as the download button
130
- iface.outputs[2].click(download_csv, inputs=[iface.outputs[1]], outputs=[iface.download_button])
131
 
132
  if __name__ == "__main__":
133
  iface.launch(debug=True)
 
102
  json_output = json.dumps(all_results, indent=4)
103
  return json_output, csv_content
104
 
105
+
106
  def download_csv(csv_content):
107
  """Creates a downloadable CSV file."""
108
  return gr.File.update(
 
110
  filename="video_analysis.csv",
111
  )
112
 
113
+ # Define Gradio interface
114
+ with gr.Blocks() as iface: # Using gr.Blocks() context
115
+ with gr.Row():
116
+ file_input = gr.File(label="Upload Videos", file_count="multiple")
117
+ question_input = gr.CheckboxGroup(["hands_free", "standing/sitting", "interaction_with_background", "indoors/outdoors"],
118
+ label="Select Questions to Apply")
119
+
120
+ with gr.Row():
121
+ json_output = gr.JSON(label="Analysis Results (JSON)")
122
+ csv_output = gr.Textbox(label="CSV Results", lines=15)
123
+
124
+ download_button = gr.Button("Download CSV") # Create button instance
125
+
126
+ # Link button click to download function
127
+ download_button.click(download_csv, inputs=csv_output, outputs=download_button)
 
128
 
129
+ # Call the analyze_videos function to handle the analysis
130
+ file_input.change(analyze_videos, inputs=[file_input, question_input], outputs=[json_output, csv_output])
131
 
132
  if __name__ == "__main__":
133
  iface.launch(debug=True)