Spaces:
Running
Running
Lorenzo Adacher
commited on
Delete gradio-interface.py
Browse files- gradio-interface.py +0 -71
gradio-interface.py
DELETED
|
@@ -1,71 +0,0 @@
|
|
| 1 |
-
import gradio as gr
|
| 2 |
-
|
| 3 |
-
# Define the function to generate the sprite based on user input
|
| 4 |
-
def generate_sprite(character_description, num_frames, character_action, viewing_direction):
|
| 5 |
-
# Combine user inputs into a single prompt
|
| 6 |
-
prompt = f"Character description: {character_description}\n" \
|
| 7 |
-
f"Character action: {character_action}\n" \
|
| 8 |
-
f"Viewing direction: {viewing_direction}\n" \
|
| 9 |
-
f"Number of frames: {num_frames}"
|
| 10 |
-
|
| 11 |
-
# Load the model from Hugging Face Hub
|
| 12 |
-
model = gr.Interface.load("huggingface/Lod34/Animator2D-v2")
|
| 13 |
-
|
| 14 |
-
# Generate the sprite using the model
|
| 15 |
-
result = model(prompt)
|
| 16 |
-
|
| 17 |
-
return result
|
| 18 |
-
|
| 19 |
-
# Configure the Gradio interface
|
| 20 |
-
with gr.Blocks(title="Animated Sprite Generator") as demo:
|
| 21 |
-
gr.Markdown("# 🎮 AI Animated Sprite Generator")
|
| 22 |
-
gr.Markdown("""
|
| 23 |
-
This tool uses an AI model to generate animated sprites based on text descriptions.
|
| 24 |
-
Enter the character description, number of frames, character action, and viewing direction to generate your animated sprite.
|
| 25 |
-
""")
|
| 26 |
-
|
| 27 |
-
with gr.Row():
|
| 28 |
-
with gr.Column():
|
| 29 |
-
# Input components
|
| 30 |
-
char_desc = gr.Textbox(label="Character Description",
|
| 31 |
-
placeholder="Ex: a knight with golden armor and a fire sword",
|
| 32 |
-
lines=3)
|
| 33 |
-
num_frames = gr.Slider(minimum=1, maximum=8, step=1, value=4,
|
| 34 |
-
label="Number of Animation Frames")
|
| 35 |
-
char_action = gr.Dropdown(
|
| 36 |
-
choices=["idle", "walk", "run", "attack", "jump", "die", "cast spell", "dance"],
|
| 37 |
-
label="Character Action",
|
| 38 |
-
value="idle"
|
| 39 |
-
)
|
| 40 |
-
view_direction = gr.Dropdown(
|
| 41 |
-
choices=["front", "back", "left", "right", "front-left", "front-right", "back-left", "back-right"],
|
| 42 |
-
label="Viewing Direction",
|
| 43 |
-
value="front"
|
| 44 |
-
)
|
| 45 |
-
generate_btn = gr.Button("Generate Animated Sprite")
|
| 46 |
-
|
| 47 |
-
with gr.Column():
|
| 48 |
-
# Output component
|
| 49 |
-
animated_output = gr.Image(label="Animated Sprite (GIF)")
|
| 50 |
-
|
| 51 |
-
# Connect the button to the function
|
| 52 |
-
generate_btn.click(
|
| 53 |
-
fn=generate_sprite,
|
| 54 |
-
inputs=[char_desc, num_frames, char_action, view_direction],
|
| 55 |
-
outputs=animated_output
|
| 56 |
-
)
|
| 57 |
-
|
| 58 |
-
# Predefined examples
|
| 59 |
-
gr.Examples(
|
| 60 |
-
[
|
| 61 |
-
["A wizard with blue cloak and pointed hat", 4, "cast spell", "front"],
|
| 62 |
-
["A warrior with heavy armor and axe", 6, "attack", "right"],
|
| 63 |
-
["A ninja with black clothes and throwing stars", 8, "run", "front-left"],
|
| 64 |
-
["A princess with golden crown and pink dress", 4, "dance", "front"]
|
| 65 |
-
],
|
| 66 |
-
inputs=[char_desc, num_frames, char_action, view_direction]
|
| 67 |
-
)
|
| 68 |
-
|
| 69 |
-
# Launch the Gradio interface
|
| 70 |
-
if __name__ == "__main__":
|
| 71 |
-
demo.launch(share=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|