Spaces:
Sleeping
Sleeping
File size: 1,553 Bytes
8b094c3 bd1c40e 8b094c3 0bc52e3 8b094c3 0bc52e3 8b094c3 0bc52e3 8b094c3 0bc52e3 8b094c3 0a8c67b 8b094c3 0bc52e3 0a8c67b 8b094c3 0a8c67b 0bc52e3 8b094c3 0bc52e3 8b094c3 bd1c40e 0a8c67b |
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 |
from transformers import pipeline
import gradio as gr
from PIL import Image
# Carrega o pipeline de geração de imagens
generator = pipeline("image-generation", model="stabilityai/stable-diffusion-2")
def generate_frame_with_model(prompt, width=256, height=256):
result = generator(prompt, height=height, width=width, num_inference_steps=50)
image = Image.open(result[0]["generated_image"]).convert("RGB")
return image
def create_animation_with_model(prompt, frame_count, duration):
frames = [generate_frame_with_model(f"{prompt}, frame {i}") for i in range(frame_count)]
gif_path = "output.gif"
frames[0].save(gif_path, save_all=True, append_images=frames[1:], duration=duration, loop=0)
return gif_path
def animate_with_model(prompt, frame_count, duration):
gif_path = create_animation_with_model(prompt, frame_count, duration)
return gif_path
# Interface Gradio
with gr.Blocks() as app:
gr.Markdown("# Gerador de Animações com Prompt de Texto")
prompt = gr.Textbox(label="Descrição do Sprite", placeholder="Descreva o sprite ou a animação que deseja criar")
frame_count = gr.Slider(label="Número de Frames", minimum=1, maximum=10, value=5, step=1)
duration = gr.Slider(label="Duração do Frame (ms)", minimum=50, maximum=500, value=100, step=10)
animation_output = gr.Image(label="Animação Gerada")
generate_button = gr.Button("Gerar Animação")
generate_button.click(animate_with_model, inputs=[prompt, frame_count, duration], outputs=animation_output)
app.launch()
|