Update app.py
Browse files
app.py
CHANGED
|
@@ -5,25 +5,51 @@ from diffusers.utils import export_to_video
|
|
| 5 |
import uuid
|
| 6 |
import os
|
| 7 |
|
|
|
|
| 8 |
model_id = "vdo/zeroscope_v2_576w"
|
|
|
|
|
|
|
|
|
|
| 9 |
pipe = DiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float32)
|
| 10 |
pipe.scheduler = DPMSolverMultistepScheduler.from_config(pipe.scheduler.config)
|
| 11 |
pipe.to("cpu")
|
|
|
|
| 12 |
|
| 13 |
def generate_video(prompt):
|
| 14 |
try:
|
| 15 |
-
#
|
| 16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
-
#
|
| 19 |
unique_name = f"result_{uuid.uuid4()}.mp4"
|
|
|
|
|
|
|
| 20 |
export_to_video(frames[0], unique_name, fps=8)
|
| 21 |
|
| 22 |
-
#
|
| 23 |
return os.path.abspath(unique_name)
|
|
|
|
| 24 |
except Exception as e:
|
| 25 |
-
print(f"HATA: {e}")
|
| 26 |
return None
|
| 27 |
|
| 28 |
-
|
| 29 |
-
demo.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
import uuid
|
| 6 |
import os
|
| 7 |
|
| 8 |
+
# Model Tanımlama
|
| 9 |
model_id = "vdo/zeroscope_v2_576w"
|
| 10 |
+
|
| 11 |
+
# Pipeline Hazırlığı
|
| 12 |
+
print("Patron motoru ısıtıyorum, model yükleniyor...")
|
| 13 |
pipe = DiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float32)
|
| 14 |
pipe.scheduler = DPMSolverMultistepScheduler.from_config(pipe.scheduler.config)
|
| 15 |
pipe.to("cpu")
|
| 16 |
+
print("Motor hazır, emirlerini bekliyorum!")
|
| 17 |
|
| 18 |
def generate_video(prompt):
|
| 19 |
try:
|
| 20 |
+
# KALİTE GÜNCELLEMESİ:
|
| 21 |
+
# num_inference_steps: 3 -> 12 (Görüntü netleşecek)
|
| 22 |
+
# num_frames: 6 -> 14 (Video süresi uzayacak)
|
| 23 |
+
# height/width: 256 -> 320x576 (YouTube Shorts için daha uygun genişlik)
|
| 24 |
+
|
| 25 |
+
frames = pipe(
|
| 26 |
+
prompt,
|
| 27 |
+
num_inference_steps=12,
|
| 28 |
+
height=320,
|
| 29 |
+
width=576,
|
| 30 |
+
num_frames=14
|
| 31 |
+
).frames
|
| 32 |
|
| 33 |
+
# Her video için benzersiz isim
|
| 34 |
unique_name = f"result_{uuid.uuid4()}.mp4"
|
| 35 |
+
|
| 36 |
+
# Video dışa aktarımı (FPS 8 olarak kaldı, daha akıcı görünür)
|
| 37 |
export_to_video(frames[0], unique_name, fps=8)
|
| 38 |
|
| 39 |
+
# n8n'in dosyayı çekebilmesi için tam yol
|
| 40 |
return os.path.abspath(unique_name)
|
| 41 |
+
|
| 42 |
except Exception as e:
|
| 43 |
+
print(f"HATA ALDIK PATRON: {e}")
|
| 44 |
return None
|
| 45 |
|
| 46 |
+
# API İsmi: 'predict' olarak sabitlendi, n8n direkt buraya vuracak
|
| 47 |
+
demo = gr.Interface(
|
| 48 |
+
fn=generate_video,
|
| 49 |
+
inputs=gr.Textbox(label="Video Prompt"),
|
| 50 |
+
outputs=gr.Video(label="Generated Video"),
|
| 51 |
+
api_name="predict"
|
| 52 |
+
)
|
| 53 |
+
|
| 54 |
+
if __name__ == "__main__":
|
| 55 |
+
demo.launch()
|