File size: 1,861 Bytes
1860d86
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import gradio as gr
import torch
from diffusers import DiffusionPipeline, DPMSolverMultistepScheduler
from diffusers.utils import export_to_video

# Gerçekten tozlu raflardan: 2023'ün ilkel text-to-video modeli.
# Inference Providers'ta yok, sadece diffusers ile lokal/Space içinde çalışır.
MODEL_ID = "ali-vilab/text-to-video-ms-1.7b-legacy"

print("Model yükleniyor (CPU), bu birkaç dakika sürebilir...")
pipe = DiffusionPipeline.from_pretrained(MODEL_ID, torch_dtype=torch.float32)
pipe.scheduler = DPMSolverMultistepScheduler.from_config(pipe.scheduler.config)
pipe.to("cpu")
print("Model hazır.")


def video_uret(prompt: str, num_steps: int, num_frames: int):
    if not prompt or not prompt.strip():
        raise gr.Error("Prompt boş olamaz.")

    video_frames = pipe(
        prompt,
        num_inference_steps=int(num_steps),
        num_frames=int(num_frames),
    ).frames[0]

    video_path = export_to_video(video_frames)
    return video_path


with gr.Blocks(title="Tozlu Raf Video Üretici") as demo:
    gr.Markdown(
        "# 📼 Tozlu Raf Video Üretici\n"
        f"Model: `{MODEL_ID}` — CPU üzerinde çalışıyor, GPU yok.\n\n"
        "**Uyarı:** Bu Space'te GPU yok. Bir video onlarca dakika sürebilir. "
        "Sabırsızsan adım/kare sayısını düşür."
    )
    prompt = gr.Textbox(
        label="Prompt",
        value="a weird creature with three legs walking backwards, melting face, bad quality vhs glitch",
    )
    with gr.Row():
        steps = gr.Slider(5, 50, value=15, step=1, label="Inference steps (az = hızlı, kalitesiz)")
        frames = gr.Slider(8, 24, value=12, step=1, label="Kare sayısı")
    btn = gr.Button("Üret (sabırlı ol)")
    output = gr.Video(label="Sonuç")

    btn.click(video_uret, inputs=[prompt, steps, frames], outputs=output)

demo.queue(max_size=5).launch()