fffiloni commited on
Commit
44ec107
1 Parent(s): 442de11

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -12
app.py CHANGED
@@ -81,7 +81,7 @@ def run_inference(temp_dir):
81
  )
82
 
83
  # Collect the output images
84
- output_images = glob(os.path.join(temp_dir, "*.png"))
85
  return output_images
86
  except subprocess.CalledProcessError as e:
87
  return f"Error during inference: {str(e)}"
@@ -96,19 +96,15 @@ def process_image(input_url):
96
  removed_bg_path, temp_dir = result # Unpack only if successful
97
 
98
  # Run inference
99
- output_images = run_inference(temp_dir)
100
 
101
- if isinstance(output_images, str) and output_images.startswith("Error"):
102
  shutil.rmtree(temp_dir)
103
  raise gr.Error(f"{output_images}") # Return the error message if inference failed
104
 
105
- # Prepare outputs for display
106
- results = []
107
- for img_path in output_images:
108
- results.append((img_path, img_path))
109
-
110
- #shutil.rmtree(temp_dir) # Cleanup temporary folder
111
- return results
112
 
113
  def gradio_interface():
114
  with gr.Blocks() as app:
@@ -118,9 +114,9 @@ def gradio_interface():
118
  input_image = gr.Image(label="Image input", type="filepath")
119
  submit_button = gr.Button("Process")
120
 
121
- output_gallery = gr.Gallery(label="Output Images")
122
 
123
- submit_button.click(process_image, inputs=[input_image], outputs=[output_gallery])
124
 
125
  return app
126
 
 
81
  )
82
 
83
  # Collect the output images
84
+ output_images = glob(os.path.join("mv_results", "*.mp4"))
85
  return output_images
86
  except subprocess.CalledProcessError as e:
87
  return f"Error during inference: {str(e)}"
 
96
  removed_bg_path, temp_dir = result # Unpack only if successful
97
 
98
  # Run inference
99
+ output_video = run_inference(temp_dir)
100
 
101
+ if isinstance(output_video, str) and output_video.startswith("Error"):
102
  shutil.rmtree(temp_dir)
103
  raise gr.Error(f"{output_images}") # Return the error message if inference failed
104
 
105
+
106
+ shutil.rmtree(temp_dir) # Cleanup temporary folder
107
+ return output_video
 
 
 
 
108
 
109
  def gradio_interface():
110
  with gr.Blocks() as app:
 
114
  input_image = gr.Image(label="Image input", type="filepath")
115
  submit_button = gr.Button("Process")
116
 
117
+ output_video= gr.Video(label="Output Video")
118
 
119
+ submit_button.click(process_image, inputs=[input_image], outputs=[output_video])
120
 
121
  return app
122