vettorazi commited on
Commit
c1a30ca
1 Parent(s): d77d6dc

from local

Browse files
Files changed (1) hide show
  1. app.py +17 -11
app.py CHANGED
@@ -1,30 +1,36 @@
1
  import gradio as gr
2
  import subprocess
3
  import os
 
 
4
 
5
  def greet(name, image):
6
  # Specify the path to the run.py script
7
  script_path = "run.py"
8
 
9
  # Specify the paths for the image, video, and output
10
- image_path = "uploaded_image.jpg"
11
- video_path = "video.mp4"
12
- output_path = "output.mp4"
 
 
 
 
 
13
 
14
- # Save the uploaded image with the appropriate file extension
15
- #image_extension = os.path.splitext(image_path)[-1].lower()
16
- #image.save(image_path, format=image_extension.lstrip('.').upper())
17
 
18
  # Construct the command to execute the run.py script with the specified arguments
19
- command = f"python {script_path} -s {image} -t {video_path} -o {output_path}"
20
 
21
  # Execute the command using subprocess
22
  subprocess.run(command, shell=True)
23
 
24
- # Return the output video as a gradio Image object
25
- #return gr.outputs.Video(file_path=output_path), ""
26
- return output_path, ""
 
 
 
27
 
28
  iface = gr.Interface(fn=greet, inputs=["text", gr.inputs.Image(type="pil")], outputs=["video", "text"])
29
  iface.launch()
30
-
 
1
  import gradio as gr
2
  import subprocess
3
  import os
4
+ import cv2
5
+ import numpy as np
6
 
7
  def greet(name, image):
8
  # Specify the path to the run.py script
9
  script_path = "run.py"
10
 
11
  # Specify the paths for the image, video, and output
12
+ image_path = os.path.abspath("uploaded_image.jpg")
13
+ video_path = os.path.abspath("video.mp4")
14
+ output_path = os.path.abspath("output.mp4")
15
+
16
+ # Convert the PIL.Image to a NumPy array
17
+ image_np = np.array(image)
18
+ # Save the uploaded image using OpenCV
19
+ cv2.imwrite(image_path, cv2.cvtColor(image_np, cv2.COLOR_RGB2BGR))
20
 
 
 
 
21
 
22
  # Construct the command to execute the run.py script with the specified arguments
23
+ command = f"python {script_path} --execution-provider cuda -s {image_path} -t {video_path} -o {output_path}"
24
 
25
  # Execute the command using subprocess
26
  subprocess.run(command, shell=True)
27
 
28
+ # Check if the output file exists
29
+ if os.path.exists(output_path):
30
+ # Return the output video as a gradio Image object
31
+ return output_path, ""
32
+ else:
33
+ return None, "Error: Failed to generate output video."
34
 
35
  iface = gr.Interface(fn=greet, inputs=["text", gr.inputs.Image(type="pil")], outputs=["video", "text"])
36
  iface.launch()