zemi123 commited on
Commit
bf5afec
·
verified ·
1 Parent(s): 1dfbe27

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -30
app.py CHANGED
@@ -2,46 +2,50 @@ import gradio as gr
2
  import replicate
3
  import os
4
 
5
- # Replicate token (Settings > Variables and secrets > Secrets)
6
- # İsim tam olarak: REPLICATE_API_TOKEN (değeri SADECE token; "export ..." yok)
7
- client = replicate.Client(api_token=os.getenv("REPLICATE_API_TOKEN"))
8
 
9
- def generate_video(image, prompt):
10
  try:
11
- # Gradio, dosya yolunu verir -> Replicate storage'a upload edip URL alıyoruz
12
- with open(image, "rb") as f:
13
- uploaded = client.files.upload(f)
14
- img_url = uploaded.url
15
-
16
- # WAN 2.1 i2v modeli
17
- out = client.run(
18
- "wavespeedai/wan-2.1-i2v-720p",
19
- input={
20
- "image": img_url,
21
- "prompt": prompt
22
- }
23
- )
24
-
25
- # Çıktı string ya da liste olabilir
26
- if isinstance(out, str):
27
- return out
28
- if isinstance(out, list):
29
- return "\n".join(out)
30
- return str(out)
31
 
32
  except Exception as e:
33
  return f"Hata: {e}"
34
 
35
  with gr.Blocks() as demo:
36
- gr.Markdown("## 🎬 WAN 2.1 Image-to-Video (Replicate)")
37
 
38
  with gr.Row():
39
- image = gr.Image(type="filepath", label="🖼️ Görsel Yükle")
40
- prompt = gr.Textbox(label="🎬 Prompt (İngilizce daha iyi sonuç verir)", lines=3)
 
 
 
 
41
 
42
  generate_btn = gr.Button("🚀 Video Oluştur")
43
- output = gr.Textbox(label="🎞️ Video URL(ler)i", lines=4)
44
 
45
- generate_btn.click(fn=generate_video, inputs=[image, prompt], outputs=output)
46
 
47
- demo.launch()
 
 
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()