File size: 4,666 Bytes
cc50ae5
87212ce
44f5493
5b51878
 
e4268e4
52f5bd3
87212ce
 
 
 
 
a9d9267
 
 
839e57a
b5b48b7
5b51878
 
 
f0fbfd0
5b51878
 
8cf4129
 
 
 
 
 
57c5d1d
8cf4129
 
 
87212ce
e4268e4
 
 
 
87212ce
e4268e4
87212ce
44f5493
 
57c5d1d
44f5493
 
 
 
b5b48b7
44f5493
 
 
 
 
 
 
 
 
 
 
 
 
 
c60777d
cc50ae5
 
f0fbfd0
cc50ae5
 
 
0488a05
cc50ae5
 
 
 
 
 
d1a176f
cc50ae5
 
 
0488a05
cc50ae5
0488a05
 
 
 
 
 
 
 
 
cc50ae5
b5b48b7
cc50ae5
 
 
0488a05
cc50ae5
 
 
 
 
 
 
 
 
c60777d
0488a05
cc50ae5
0488a05
cc50ae5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
32b92c1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
import gradio as gr
from gradio_client import Client
import requests
from deep_translator import GoogleTranslator
from langdetect import detect
import re

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 Exception as e:
        error_message = str(e)
        match = re.search(r'You have exceeded your GPU quota \((\d+:\d+:\d+) left vs. \d+s requested\). Please retry in (\d+:\d+:\d+)\.', error_message)
        if match:
            wait_time = match.group(2)
            raise gr.Error(f"У модели сработало ограничение (Слишком часто), попробуйте ещё раз в *время: {wait_time}*")
        else:
            raise gr.Error(f"Произошла ошибка при подключении к API: {error_message}. Повторите попытку позже или обратитесь к администраторам 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='Prompt ရေးပါ', placeholder='ဥပမာ: dragon is flying over cloud'
            )
        with gr.Row():
            select_base = gr.Dropdown(
                label='Styles',
                choices=[
                    "Cartoon", 
                    "Realistic",
                    "3d",
                    "Anime",
                ],
                value="3d",
                interactive=True
            )
            select_motion = gr.Dropdown(
                label='Movements',
                choices=[
                    ("Default", ""),
                    ("Zoom in", "guoyww/animatediff-motion-lora-zoom-in"),
                    ("Zoom out", "guoyww/animatediff-motion-lora-zoom-out"),
                    ("Tilt up", "guoyww/animatediff-motion-lora-tilt-up"),
                    ("Tilt down", "guoyww/animatediff-motion-lora-tilt-down"),
                    ("Pan left", "guoyww/animatediff-motion-lora-pan-left"),
                    ("Pan right", "guoyww/animatediff-motion-lora-pan-right"),
                    ("Rolling Anticlockwise", "guoyww/animatediff-motion-lora-rolling-anticlockwise"),
                    ("Rolling Clockwise", "guoyww/animatediff-motion-lora-rolling-clockwise"),
                ],
                value="",
                interactive=True
            )
            select_step = gr.Dropdown(
                label='ထုတ်မည့်အဆင့်များ (Qualit)',
                choices=[
                    ('1-Step', 1), 
                    ('2-Step', 2),
                    ('4-Step', 4),
                    ('8-Step', 8),
                ],
                value=4,
                interactive=True
            )
        with gr.Row():
            submit = gr.Button("ဖန်တီးမယ်", variant='primary')
    video = gr.Video(
        label='ဖန်တီးထားသည့် video',
        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(show_api=False, share=False)