Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,46 +2,50 @@ import gradio as gr
|
|
| 2 |
import replicate
|
| 3 |
import os
|
| 4 |
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
client = replicate.Client(api_token=os.getenv("REPLICATE_API_TOKEN"))
|
| 8 |
|
| 9 |
-
def generate_video(
|
| 10 |
try:
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
return "\n".join(out)
|
| 30 |
-
return str(
|
| 31 |
|
| 32 |
except Exception as e:
|
| 33 |
return f"Hata: {e}"
|
| 34 |
|
| 35 |
with gr.Blocks() as demo:
|
| 36 |
-
gr.Markdown("#
|
| 37 |
|
| 38 |
with gr.Row():
|
| 39 |
-
|
| 40 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
|
| 42 |
generate_btn = gr.Button("🚀 Video Oluştur")
|
| 43 |
-
|
| 44 |
|
| 45 |
-
generate_btn.click(fn=generate_video, inputs=[
|
| 46 |
|
| 47 |
-
|
|
|
|
|
|
| 2 |
import replicate
|
| 3 |
import os
|
| 4 |
|
| 5 |
+
TITLE = "🎬 WAN 2.1 Image-to-Video (Replicate)"
|
| 6 |
+
DESC = "Bir görsel yükle, kısa bir İngilizce sahne/prompt yaz ve 720p kısa video üret. (Replicate/WAN 2.1)"
|
|
|
|
| 7 |
|
| 8 |
+
def generate_video(image_path, prompt):
|
| 9 |
try:
|
| 10 |
+
if not image_path:
|
| 11 |
+
return "Lütfen önce bir görsel yükleyin."
|
| 12 |
+
# Replicate tokene gerek yok; HuggingFace 'Secrets' kısmında REPLICATE_API_TOKEN olarak tanımlı olmalı
|
| 13 |
+
# Replicate Python client dosya 'rb' bekler:
|
| 14 |
+
with open(image_path, "rb") as f:
|
| 15 |
+
output = replicate.run(
|
| 16 |
+
"wavespeedai/wan-2.1-i2v-720p",
|
| 17 |
+
input={
|
| 18 |
+
"image": f,
|
| 19 |
+
"prompt": prompt or ""
|
| 20 |
+
}
|
| 21 |
+
)
|
| 22 |
+
|
| 23 |
+
# Çoğu model list[str] (URL listesi) döner
|
| 24 |
+
if isinstance(output, list):
|
| 25 |
+
return "\n".join(output)
|
| 26 |
+
if isinstance(output, dict) and "output" in output:
|
| 27 |
+
out = output["output"]
|
| 28 |
+
return "\n".join(out) if isinstance(out, list) else str(out)
|
| 29 |
+
return str(output)
|
| 30 |
|
| 31 |
except Exception as e:
|
| 32 |
return f"Hata: {e}"
|
| 33 |
|
| 34 |
with gr.Blocks() as demo:
|
| 35 |
+
gr.Markdown(f"# {TITLE}\n{DESC}")
|
| 36 |
|
| 37 |
with gr.Row():
|
| 38 |
+
image_in = gr.Image(type="filepath", label="🖼️ Görsel Yükle")
|
| 39 |
+
prompt_in = gr.Textbox(
|
| 40 |
+
label="🎬 Prompt (İngilizce daha iyi sonuç verir)",
|
| 41 |
+
placeholder="e.g. the woman's hair moves gently in the wind",
|
| 42 |
+
lines=3
|
| 43 |
+
)
|
| 44 |
|
| 45 |
generate_btn = gr.Button("🚀 Video Oluştur")
|
| 46 |
+
url_out = gr.Textbox(label="📼 Video URL(ler)i", lines=6)
|
| 47 |
|
| 48 |
+
generate_btn.click(fn=generate_video, inputs=[image_in, prompt_in], outputs=[url_out])
|
| 49 |
|
| 50 |
+
if __name__ == "__main__":
|
| 51 |
+
demo.launch()
|