Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from gradio_client import Client
|
| 3 |
+
import os
|
| 4 |
+
import shutil
|
| 5 |
+
import tempfile
|
| 6 |
+
import zipfile
|
| 7 |
+
|
| 8 |
+
def generate_frame(client, prompt, frame_number, total_frames):
|
| 9 |
+
adjusted_prompt = f"{prompt} - frame {frame_number} of {total_frames}"
|
| 10 |
+
|
| 11 |
+
result = client.predict(
|
| 12 |
+
prompt=adjusted_prompt,
|
| 13 |
+
is_negative="(deformed, distorted, disfigured), poorly drawn, bad anatomy, wrong anatomy, extra limb, missing limb, floating limbs, (mutated hands and fingers), disconnected limbs, mutation, mutated, ugly, disgusting, blurry, amputation, misspellings, typos",
|
| 14 |
+
steps=35,
|
| 15 |
+
cfg_scale=7,
|
| 16 |
+
sampler="DPM++ 2M Karras",
|
| 17 |
+
seed=-1,
|
| 18 |
+
strength=0.7,
|
| 19 |
+
huggingface_api_key="",
|
| 20 |
+
use_dev=True,
|
| 21 |
+
enhance_prompt_style="Cartoon",
|
| 22 |
+
enhance_prompt_option=True,
|
| 23 |
+
nemo_enhance_prompt_style="Cartoon",
|
| 24 |
+
use_mistral_nemo=True,
|
| 25 |
+
api_name="/query"
|
| 26 |
+
)
|
| 27 |
+
return result
|
| 28 |
+
|
| 29 |
+
def generate_video_frames(prompt, num_frames, progress=gr.Progress()):
|
| 30 |
+
client = Client("K00B404/FLUX.1-Dev-Serverless-darn-enhanced-prompt")
|
| 31 |
+
|
| 32 |
+
with tempfile.TemporaryDirectory() as temp_dir:
|
| 33 |
+
frame_paths = []
|
| 34 |
+
for i in progress.tqdm(range(num_frames)):
|
| 35 |
+
tmp_image_path, used_seed, enhanced_prompt = generate_frame(client, prompt, i+1, num_frames)
|
| 36 |
+
|
| 37 |
+
destination_path = os.path.join(temp_dir, f"frame_{i:03d}.png")
|
| 38 |
+
shutil.copy(tmp_image_path, destination_path)
|
| 39 |
+
frame_paths.append(destination_path)
|
| 40 |
+
|
| 41 |
+
yield f"Generated frame {i+1}/{num_frames}\nSeed: {used_seed}\nEnhanced prompt: {enhanced_prompt}"
|
| 42 |
+
|
| 43 |
+
zip_path = os.path.join(temp_dir, "video_frames.zip")
|
| 44 |
+
with zipfile.ZipFile(zip_path, 'w') as zipf:
|
| 45 |
+
for file in frame_paths:
|
| 46 |
+
zipf.write(file, os.path.basename(file))
|
| 47 |
+
|
| 48 |
+
yield f"Generated {num_frames} frames. Downloading ZIP file..."
|
| 49 |
+
return zip_path
|
| 50 |
+
|
| 51 |
+
def launch_interface(prompt, num_frames):
|
| 52 |
+
output = generate_video_frames(prompt, num_frames)
|
| 53 |
+
return output
|
| 54 |
+
|
| 55 |
+
# Define the Gradio interface
|
| 56 |
+
iface = gr.Interface(
|
| 57 |
+
fn=launch_interface,
|
| 58 |
+
inputs=[
|
| 59 |
+
gr.Textbox(label="Prompt", placeholder="Enter your prompt here..."),
|
| 60 |
+
gr.Slider(minimum=1, maximum=50, step=1, label="Number of Frames", value=10)
|
| 61 |
+
],
|
| 62 |
+
outputs=[
|
| 63 |
+
gr.Textbox(label="Progress", lines=5),
|
| 64 |
+
gr.File(label="Download Frames")
|
| 65 |
+
],
|
| 66 |
+
title="Video Frame Generator",
|
| 67 |
+
description="Generate a series of video frames using the FLUX.1 model.",
|
| 68 |
+
allow_flagging="never"
|
| 69 |
+
)
|
| 70 |
+
|
| 71 |
+
# Launch the interface
|
| 72 |
+
iface.launch()
|