Commit
·
333f8a8
1
Parent(s):
c4625d9
Update base/app.py
Browse files- base/app.py +15 -4
base/app.py
CHANGED
@@ -73,11 +73,22 @@ def infer(secret_token, prompt):
|
|
73 |
videos = model(prompt, video_length=16, height = 320, width= 512, num_inference_steps=ddim_steps, guidance_scale=cfg).video
|
74 |
if not os.path.exists(args.output_folder):
|
75 |
os.mkdir(args.output_folder)
|
76 |
-
torchvision.io.write_video(args.output_folder + prompt[0:30].replace(' ', '_') + '-'+str(seed_inp)+'-'+str(ddim_steps)+'-'+str(cfg)+ '-.mp4', videos[0], fps=8)
|
77 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
78 |
|
79 |
-
|
|
|
|
|
|
|
|
|
80 |
|
|
|
81 |
|
82 |
|
83 |
with gr.Blocks() as demo:
|
@@ -101,10 +112,10 @@ with gr.Blocks() as demo:
|
|
101 |
|
102 |
with gr.Column():
|
103 |
submit_btn = gr.Button("Generate video")
|
104 |
-
|
105 |
|
106 |
inputs = [secret_token, prompt, seed_inp, ddim_steps, cfg, infer_type]
|
107 |
-
outputs = [
|
108 |
|
109 |
submit_btn.click(infer, inputs, outputs)
|
110 |
|
|
|
73 |
videos = model(prompt, video_length=16, height = 320, width= 512, num_inference_steps=ddim_steps, guidance_scale=cfg).video
|
74 |
if not os.path.exists(args.output_folder):
|
75 |
os.mkdir(args.output_folder)
|
|
|
76 |
|
77 |
+
video_path = args.output_folder + prompt[0:30].replace(' ', '_') + '-'+str(seed_inp)+'-'+str(ddim_steps)+'-'+str(cfg)+ '-.mp4'
|
78 |
+
|
79 |
+
torchvision.io.write_video(outputPath, videos[0], fps=8)
|
80 |
+
|
81 |
+
# Read the content of the video file and encode it to base64
|
82 |
+
with open(video_path, "rb") as video_file:
|
83 |
+
video_base64 = base64.b64encode(video_file.read()).decode('utf-8')
|
84 |
|
85 |
+
# Prepend the appropriate data URI header with MIME type
|
86 |
+
video_data_uri = 'data:video/mp4;base64,' + video_base64
|
87 |
+
|
88 |
+
# Clean up the video file to avoid filling up storage
|
89 |
+
# os.remove(video_path)
|
90 |
|
91 |
+
return video_data_uri
|
92 |
|
93 |
|
94 |
with gr.Blocks() as demo:
|
|
|
112 |
|
113 |
with gr.Column():
|
114 |
submit_btn = gr.Button("Generate video")
|
115 |
+
base64_out = gr.Textbox(label="Base64 Video")
|
116 |
|
117 |
inputs = [secret_token, prompt, seed_inp, ddim_steps, cfg, infer_type]
|
118 |
+
outputs = [base64_out]
|
119 |
|
120 |
submit_btn.click(infer, inputs, outputs)
|
121 |
|