Anthoniomada commited on
Commit
9aed51b
·
verified ·
1 Parent(s): 22836c7

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +74 -0
app.py ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import torch
3
+ import tempfile
4
+ from diffusers import DiffusionPipeline
5
+ from diffusers.utils import export_to_video
6
+
7
+ # Model ID specified in your request
8
+ MODEL_ID = "DollasAndSpence/LTX2.3-ICEdit-Insight"
9
+
10
+ # Load the pipeline
11
+ # We use bfloat16 for optimized memory usage on modern GPUs
12
+ pipe = DiffusionPipeline.from_pretrained(
13
+ MODEL_ID,
14
+ torch_dtype=torch.bfloat16,
15
+ )
16
+
17
+ # Offload model to CPU when not actively computing to save VRAM
18
+ pipe.enable_model_cpu_offload()
19
+
20
+ def process_video(prompt, input_video_path, inference_steps, guidance_scale):
21
+ if not input_video_path:
22
+ raise gr.Error("Please provide an input video.")
23
+
24
+ kwargs = {
25
+ "prompt": prompt,
26
+ "video": input_video_path,
27
+ "num_inference_steps": inference_steps,
28
+ "guidance_scale": guidance_scale,
29
+ "output_type": "np",
30
+ }
31
+
32
+ # Generate the edited/restored frames
33
+ # Depending on the exact wrapper, LTX may require frame rounding (e.g. 8k + 1 rule)
34
+ try:
35
+ output = pipe(**kwargs)
36
+ except Exception as e:
37
+ raise gr.Error(f"Inference failed: {str(e)}")
38
+
39
+ # Export the processed frames to a temporary mp4 file
40
+ out_file = tempfile.NamedTemporaryFile(suffix=".mp4", delete=False).name
41
+ export_to_video(output.frames[0], out_file, fps=24)
42
+
43
+ return out_file
44
+
45
+ # Build the Gradio UI
46
+ with gr.Blocks(title="LTX2.3 ICEdit-Insight Video Restoration") as demo:
47
+ gr.Markdown(f"# 🎥 {MODEL_ID} Video Editor")
48
+ gr.Markdown("Upload a video and provide an instruction to remove AI glitches, watermarks, subtitles, or enhance HD details.")
49
+
50
+ with gr.Row():
51
+ with gr.Column():
52
+ input_vid = gr.Video(label="Input Video (To be fixed/edited)")
53
+ prompt = gr.Textbox(
54
+ label="Editing Instruction",
55
+ placeholder="e.g., Clean up AI inpainting glitches, remove watermarks, enhance details..."
56
+ )
57
+
58
+ with gr.Accordion("Advanced Settings", open=False):
59
+ steps = gr.Slider(minimum=1, maximum=50, value=30, step=1, label="Inference Steps")
60
+ cfg = gr.Slider(minimum=1.0, maximum=15.0, value=4.0, step=0.1, label="Guidance Scale")
61
+
62
+ run_btn = gr.Button("Generate Fix", variant="primary")
63
+
64
+ with gr.Column():
65
+ output_vid = gr.Video(label="Restored Output Video")
66
+
67
+ run_btn.click(
68
+ fn=process_video,
69
+ inputs=[prompt, input_vid, steps, cfg],
70
+ outputs=output_vid
71
+ )
72
+
73
+ if __name__ == "__main__":
74
+ demo.launch()