Rooni commited on
Commit
aecddc5
1 Parent(s): 97afb33

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -20
app.py CHANGED
@@ -1,7 +1,7 @@
1
  import gradio as gr
2
  import os
3
- import requests
4
- from huggingface_hub import cached_download, hf_hub_url
5
 
6
 
7
  MORE = """ ## TRY Other Models
@@ -11,24 +11,23 @@ MORE = """ ## TRY Other Models
11
 
12
  # Function
13
  def generate_image(prompt, base="Anime", motion="", step=8, progress=gr.Progress()):
14
- API_URL = "https://api-inference.huggingface.co/models/KingNish/Instant-Video/generate_image_1"
15
- headers = {"Authorization": f"Bearer {os.environ.get('HF_API_TOKEN')}"} # Замените на ваш токен Hugging Face API
16
-
17
- payload = {
18
- "inputs": prompt,
19
- "options": {
20
- "base": base,
21
- "motion": motion,
22
- "step": step
23
- }
24
- }
25
-
26
- response = requests.post(API_URL, headers=headers, json=payload)
27
- response.raise_for_status()
28
-
29
- video_url = response.json()[0]['video']
30
- video_path = cached_download(video_url)
31
- return video_path
32
 
33
  # Gradio Interface
34
  with gr.Blocks(css="style.css") as demo:
 
1
  import gradio as gr
2
  import os
3
+ from gradio_client import Client
4
+ import time
5
 
6
 
7
  MORE = """ ## TRY Other Models
 
11
 
12
  # Function
13
  def generate_image(prompt, base="Anime", motion="", step=8, progress=gr.Progress()):
14
+ retries = 3
15
+ for i in range(retries):
16
+ try:
17
+ result = client.predict(
18
+ prompt=prompt,
19
+ base=base,
20
+ motion=motion,
21
+ step=step,
22
+ api_name="/generate_image_1"
23
+ )
24
+ video_path = result["video"]
25
+ return video_path
26
+ except ValueError as e:
27
+ print(f"Ошибка подключения. Попытка {i+1} из {retries}.")
28
+ raise gr.Info(f"Ошибка подключения. Попытка {i+1} из {retries}.")
29
+ time.sleep(5) # Пауза перед следующей попыткой
30
+ raise gr.Error("Не удалось подключиться к API. Повторите попытку позже.")
 
31
 
32
  # Gradio Interface
33
  with gr.Blocks(css="style.css") as demo: