halilcelik commited on
Commit
4a4583b
·
verified ·
1 Parent(s): 81f91c3

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -0
app.py ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import torch
3
+ from diffusers import DiffusionPipeline, DPMSolverMultistepScheduler
4
+ from diffusers.utils import export_to_video
5
+ import uuid
6
+
7
+ # Model yükleme (Hafif ve hızlı versiyon)
8
+ pipe = DiffusionPipeline.from_pretrained("ceruulean/zeroscope_v2_576w", torch_dtype=torch.float16 if torch.cuda.is_available() else torch.float32)
9
+ pipe.scheduler = DPMSolverMultistepScheduler.from_config(pipe.scheduler.config)
10
+
11
+ # Eğer GPU varsa kullan, yoksa CPU (Free tier için otomatik ayar)
12
+ if torch.cuda.is_available():
13
+ pipe.enable_model_cpu_offload()
14
+
15
+ def generate_video(prompt):
16
+ video_frames = pipe(prompt, num_inference_steps=20, height=320, width=576, num_frames=24).frames
17
+ video_path = f"video_{uuid.uuid4()}.mp4"
18
+ export_to_video(video_frames[0], video_path)
19
+ return video_path
20
+
21
+ # Gradio Arayüzü
22
+ with gr.Blocks() as demo:
23
+ prompt = gr.Textbox(label="Video Promptu")
24
+ video_output = gr.Video(label="Üretilen Video")
25
+ generate_btn = gr.Button("Üret")
26
+
27
+ generate_btn.click(fn=generate_video, inputs=prompt, outputs=video_output)
28
+
29
+ demo.launch()