fffiloni commited on
Commit
5e44253
1 Parent(s): 21c2d2b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +50 -21
app.py CHANGED
@@ -1,39 +1,68 @@
1
  import gradio as gr
2
  import os
 
 
 
 
3
  token = os.environ.get('HF_TOKEN')
4
  pix2pix = gr.Blocks.load(name="spaces/fffiloni/instruct-pix2pix-clone", api_key=token)
5
 
6
- def infer(prompt,image):
7
- result = pix2pix(prompt,
8
- 5.5,
9
- 1.5,
10
- image,
11
- 15,
12
- "",
13
- 512,
14
- 512,
15
- 0,
16
- fn_index=0)
17
- print(result)
18
- print(result[0])
19
- print(result[0][0])
20
- # return "done"
21
- images = [os.path.join(result[0], img) for img in os.listdir(result[0])]
22
- return images[0]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
23
 
24
  with gr.Blocks() as demo:
25
  with gr.Column():
26
  prompt = gr.Textbox(placeholder="enter prompt")
27
- image = gr.Image(source="upload", type="filepath")
28
- image_out = gr.Image()
29
  #text_out = gr.Textbox()
30
  submit_btn = gr.Button("go")
31
 
32
  inputs = [
33
  prompt,
34
- image
35
  ]
36
- outputs = [image_out]
37
  #outputs = [text_out]
38
  submit_btn.click(infer, inputs, outputs)
39
 
 
1
  import gradio as gr
2
  import os
3
+ import cv2
4
+ import numpy as np
5
+ from moviepy.editor import *
6
+
7
  token = os.environ.get('HF_TOKEN')
8
  pix2pix = gr.Blocks.load(name="spaces/fffiloni/instruct-pix2pix-clone", api_key=token)
9
 
10
+ def get_frames(video_in):
11
+ frames = []
12
+ # Opens the Video file
13
+ cap= cv2.VideoCapture(video_in)
14
+ fps = cap.get(cv2.CAP_PROP_FPS)
15
+ i=0
16
+ while(cap.isOpened()):
17
+ ret, frame = cap.read()
18
+ if ret == False:
19
+ break
20
+ cv2.imwrite('kang'+str(i)+'.jpg',frame)
21
+ frames.append('kang'+str(i)+'.jpg')
22
+ i+=1
23
+
24
+ cap.release()
25
+ cv2.destroyAllWindows()
26
+
27
+ return frames, fps
28
+
29
+ def create_video(frames, fps):
30
+
31
+ clip = ImageSequenceClip(frames, fps=fps)
32
+ clip.write_videofile("movie.mp4", fps=fps)
33
+
34
+ return 'movie.mp4'
35
+
36
+
37
+ def infer(prompt,video_in):
38
+ break_vid = get_frames(video_in)
39
+
40
+ frames_list= break_vid[0]
41
+ fps = break_vid[1]
42
+ result_frames = []
43
+
44
+ for i in frames_list:
45
+ pix2pix_img = pix2pix(prompt,5.5,1.5,i,15,"",512,512,0,fn_index=0)
46
+ images = [os.path.join(pix2pix_img[0], img) for img in os.listdir(pix2pix_img[0])]
47
+ result_frames.append(images[0])
48
+
49
+ final_vid = create_video(result_frames, fps)
50
+
51
+ return final_vid
52
 
53
  with gr.Blocks() as demo:
54
  with gr.Column():
55
  prompt = gr.Textbox(placeholder="enter prompt")
56
+ video_inp = gr.Video(source="upload", type="filepath")
57
+ video_out = gr.Video()
58
  #text_out = gr.Textbox()
59
  submit_btn = gr.Button("go")
60
 
61
  inputs = [
62
  prompt,
63
+ video_inp
64
  ]
65
+ outputs = [video]
66
  #outputs = [text_out]
67
  submit_btn.click(infer, inputs, outputs)
68