File size: 1,553 Bytes
ff3c6aa
998b8a0
ff3c6aa
0b11a54
1c71d5b
 
 
998b8a0
0b11a54
ff3c6aa
 
 
 
 
 
 
44c8dae
ff3c6aa
0b11a54
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c02f1e3
 
0b11a54
 
b841619
0b11a54
c91eb55
fe2bf46
c02f1e3
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
import os
import gradio as gr
from stability_sdk.api import Context
from stability_sdk.animation import AnimationArgs, Animator
from dotenv import load_dotenv

load_dotenv(".env") 

STABILITY_HOST = "grpc.stability.ai:443" 
STABILITY_KEY = os.getenv("STABILITY_KEY")

# Connect to Stability API
context = Context(STABILITY_HOST, STABILITY_KEY)

# Test the connection
context.get_user_info()
print("Connection successfuly!")

def anim(f_promt, s_promt):
    # Configure the animation
    args = AnimationArgs()
    args.interpolate_prompts = True
    args.locked_seed = True
    args.max_frames = 48
    args.seed = 42
    args.strength_curve = "0:(0)"
    args.diffusion_cadence_curve = "0:(4)"
    args.cadence_interp = "film"

    animation_prompts = {
        0: f_promt,
        24: s_promt,
    }
    negative_prompt = ""

    # Create Animator object to orchestrate the rendering
    animator = Animator(
        api_context=context,
        animation_prompts=animation_prompts,
        negative_prompt=negative_prompt,
        args=args
    )

    # Render each frame of animation
    for idx, frame in enumerate(animator.render()):
        frame.save(f"frame_{idx:05d}.png")

with gr.Blocks() as demo:
    gr.Markdown("Stability Animation")
    f_promt = gr.Textbox(label="Fist Promt", value="a photo of a cute cat")
    s_promt = gr.Textbox(label="Fist Promt", value="a photo of a cute dog")
    outimg = gr.Files()
    btn = gr.Button('Anim')
    btn.click(fn=anim, inputs=[f_promt,s_promt], outputs=[outimg],api_name="AnimAPI")

demo.launch()