Instant-Video / app.py
Rooni's picture
Update app.py
5b51878 verified
raw
history blame
4.28 kB
import gradio as gr
import os
from gradio_client import Client
import time
import requests
from deep_translator import GoogleTranslator
from langdetect import detect
MORE = """ ## TRY Other Models
### JARVIS: Your VOICE Assistant -> https://huggingface.co/spaces/KingNish/JARVIS
### Instant Image: 4k images in 5 Second -> https://huggingface.co/spaces/KingNish/Instant-Image
"""
# Gradio Client
client = Client("KingNish/Instant-Video")
# Function
def generate_image(prompt, base="Anime", motion="", step=8, progress=gr.Progress()):
language = detect(prompt)
if language != 'en':
prompt = GoogleTranslator(source=language, target='en').translate(prompt)
try:
result = client.predict(
prompt=prompt,
base=base,
motion=motion,
step=step,
api_name="/instant_video"
)
video_path = result["video"]
return video_path
except ValueError as e:
print(f"Ошибка подключения.")
raise gr.Error("Не удалось подключиться к API. Повторите попытку позже или обратитесь к администраторам Neurix.")
# Ссылка на файл CSS
css_url = "https://neurixyufi-aihub.static.hf.space/style.css"
# Получение CSS по ссылке
response = requests.get(css_url)
css = response.text
# Gradio Interface
with gr.Blocks(css=css) as demo:
gr.HTML(
"""
<script>
var head = document.getElementsByTagName('head')[0];
var link = document.createElement('link');
link.rel = 'stylesheet';
link.type = 'text/css';
link.href = 'style.css';
head.appendChild(link);
</script>
"""
)
with gr.Column():
with gr.Row():
prompt = gr.Textbox(
label='Описание'
)
with gr.Row():
select_base = gr.Dropdown(
label='Стиль',
choices=[
"Cartoon",
"Realistic",
"3d",
"Anime",
],
value="Anime",
interactive=True
)
select_motion = gr.Dropdown(
label='Движение',
choices=[
("По умолчанию", ""),
("Приближение", "guoyww/animatediff-motion-lora-zoom-in"),
("Отдаление", "guoyww/animatediff-motion-lora-zoom-out"),
("Наклон вверх", "guoyww/animatediff-motion-lora-tilt-up"),
("Наклон вниз", "guoyww/animatediff-motion-lora-tilt-down"),
("Панорама влево", "guoyww/animatediff-motion-lora-pan-left"),
("Панорама вправо", "guoyww/animatediff-motion-lora-pan-right"),
("Поворот влево", "guoyww/animatediff-motion-lora-rolling-anticlockwise"),
("Поворот вправо", "guoyww/animatediff-motion-lora-rolling-clockwise"),
],
value="",
interactive=True
)
select_step = gr.Dropdown(
label='Шаги вывода',
choices=[
('1-Step', 1),
('2-Step', 2),
('4-Step', 4),
('8-Step', 8),
],
value=4,
interactive=True
)
with gr.Row():
submit = gr.Button(
scale=1,
variant='primary'
)
video = gr.Video(
label='Созданое видео',
autoplay=True,
height=512,
width=512,
elem_id="video_output"
)
prompt.submit(
fn=generate_image,
inputs=[prompt, select_base, select_motion, select_step],
outputs=video,
)
submit.click(
fn=generate_image,
inputs=[prompt, select_base, select_motion, select_step],
outputs=video,
)
demo.queue(max_size=250).launch()