AngeT10 commited on
Commit
99dd96c
·
verified ·
1 Parent(s): edbd98e

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +44 -0
app.py ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ import gradio as gr
3
+ from diffnext.pipelines import NOVAPipeline
4
+ from diffnext.utils import export_to_image, export_to_video
5
+
6
+ # Inizializzazione del modello
7
+ model_id = "BAAI/nova-d48w1024-osp480"
8
+ model_args = {"torch_dtype": torch.float16, "trust_remote_code": True}
9
+ pipe = NOVAPipeline.from_pretrained(model_id, **model_args)
10
+ pipe = pipe.to("cuda")
11
+
12
+ # Funzioni per generare immagine e video
13
+ def generate_image(prompt: str):
14
+ image = pipe(prompt, max_latent_length=1).frames[0, 0]
15
+ export_to_image(image, "output.jpg")
16
+ return "output.jpg"
17
+
18
+ def generate_video(prompt: str):
19
+ video = pipe(prompt, max_latent_length=9).frames[0]
20
+ export_to_video(video, "output.mp4", fps=12)
21
+ return "output.mp4"
22
+
23
+ def generate_video_high_quality(prompt: str):
24
+ video = pipe(
25
+ prompt,
26
+ max_latent_length=9,
27
+ num_inference_steps=128,
28
+ num_diffusion_steps=100,
29
+ ).frames[0]
30
+ export_to_video(video, "output_v2.mp4", fps=12)
31
+ return "output_v2.mp4"
32
+
33
+
34
+ )
35
+
36
+ iface3 = gr.Interface(
37
+ fn=generate_video_high_quality,
38
+ inputs=gr.Textbox(label="Enter Prompt"),
39
+ outputs=gr.Video(label="High Quality Generated Video"),
40
+ live=True
41
+ )
42
+
43
+
44
+ iface3.launch(share=True)