Spaces:
Runtime error
Runtime error
# Import the necessary libraries for creating the interface | |
import gradio as gr | |
from transformers import pipeline | |
from diffusers import DiffusionPipeline | |
pipeline = DiffusionPipeline.from_pretrained("vdo/Hotshot-XL") | |
pipeline = DiffusionPipeline.from_pretrained("sanjay7178/diffscaler-XL") | |
pipeline = DiffusionPipeline.from_pretrained("hotshotco/Hotshot-XL") | |
# Define a function to apply regex choices to the prompt text | |
def apply_regex_choices(text): | |
import re # Import the regular expressions module | |
pattern = re.compile(r'\(([^)]+)\)') # Define the regex pattern to find text within parentheses | |
while True: | |
match = pattern.search(text) # Search for the pattern in the text | |
if not match: # If no match is found, break the loop | |
break | |
choices = match.group(1).split('|') # Split the choices within the parentheses by '|' | |
chosen = choices[0] # Select the first option from the choices (or use random.choice(choices) for randomness) | |
text = text[:match.start()] + chosen + text[match.end():] # Replace the matched text with the chosen option | |
return text # Return the modified text | |
# Define a function to generate the GIF using the provided prompt | |
def generate_gif(prompt): | |
final_prompt = apply_regex_choices(prompt) # Apply regex choices to the prompt | |
gif_generator = pipeline('text-to-video', model='hotshotco/Hotshot-XL') # Load the text-to-video pipeline with the specified model | |
gif = gif_generator(final_prompt) # Generate the GIF using the final prompt | |
with open("output.gif", "wb") as f: # Open a file to save the GIF | |
f.write(gif) # Write the GIF to the file | |
return "output.gif" # Return the file path of the generated GIF | |
# Define the default prompt template with regex options | |
prompt_template = """ | |
Create a GIF of a 'Technical Difficulties' television program interruption. The scene should show colored glitchy and typical 'technical difficulties' cable interruptions, (using|with) demonic symbols glitching out along with the colors of the usual 'tech difficulties' broadcasts. The setting should be (an older|a vintage) tv cable broadcast signal interruption. The style should be a realistic cable interruption interlaced with (demonic imagery|dark symbols) glitching out along with the typical color page of interruption in connection. The GIF should last for 1 second. | |
""" | |
# Create a Gradio interface | |
iface = gr.Interface( | |
fn=generate_gif, # The function to call when the user interacts with the interface | |
inputs=gr.Textbox(lines=10, placeholder="Enter your custom prompt here or use the default template", value=prompt_template), # Input textbox for the prompt | |
outputs="file", # Output will be a file (the generated GIF) | |
title="Structured Prompt GIF Generator", # Title of the interface | |
description="Generate GIFs from text prompts using the Hotshot-XL model. Customize the prompt or use the default template to generate GIFs.", # Description of the interface | |
examples=[ # Adding example prompts | |
["Create a GIF of a cat jumping over a fence in a sunny backyard. The style should be realistic. The GIF should last for 2 seconds."], | |
["Create a GIF of a rocket launching into space. The scene should show the rocket taking off from the launchpad with smoke and fire. The style should be cinematic. The GIF should last for 3 seconds."] | |
] | |
) | |
# Launch the Gradio interface | |
iface.launch() | |