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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import time
|
| 3 |
+
import random
|
| 4 |
+
|
| 5 |
+
# Mock function to simulate video generation.
|
| 6 |
+
# In a real application, you would replace this logic with a model inference call
|
| 7 |
+
# (e.g., using diffusers, AnimateDiff, or an API like OpenAI Sora or Stability AI).
|
| 8 |
+
def generate_video_mock(prompt, negative_prompt, duration, seed):
|
| 9 |
+
"""
|
| 10 |
+
Simulates the video generation process.
|
| 11 |
+
Returns a sample video path after a simulated delay.
|
| 12 |
+
"""
|
| 13 |
+
if not prompt:
|
| 14 |
+
raise gr.Error("Please enter a text prompt to generate a video.")
|
| 15 |
+
|
| 16 |
+
# Simulate processing time based on duration
|
| 17 |
+
processing_time = duration * 0.5
|
| 18 |
+
time.sleep(processing_time)
|
| 19 |
+
|
| 20 |
+
# In a real scenario, this would be the path to the generated video file.
|
| 21 |
+
# Here we return a sample video from Gradio's assets for demonstration.
|
| 22 |
+
sample_video = "https://gradio-builds.s3.amazonaws.com/assets/world.mp4"
|
| 23 |
+
|
| 24 |
+
# Add some metadata to the output for display
|
| 25 |
+
return sample_video, f"Generated in {processing_time:.2f}s using seed {seed}"
|
| 26 |
+
|
| 27 |
+
def update_seed():
|
| 28 |
+
"""Generates a random seed for the next generation."""
|
| 29 |
+
return random.randint(0, 1000000)
|
| 30 |
+
|
| 31 |
+
# Gradio 6 Application
|
| 32 |
+
# Note: gr.Blocks() takes NO parameters in Gradio 6. All config goes in launch().
|
| 33 |
+
with gr.Blocks() as demo:
|
| 34 |
+
|
| 35 |
+
# Header Section
|
| 36 |
+
gr.Markdown(
|
| 37 |
+
"""
|
| 38 |
+
# 🎬 Text to Video Studio
|
| 39 |
+
|
| 40 |
+
Transform your imagination into motion. Enter a text prompt below to generate a video clip.
|
| 41 |
+
|
| 42 |
+
<div style="text-align: right; font-size: 0.9em;">
|
| 43 |
+
<a href="https://huggingface.co/spaces/akhaliq/anycoder" target="_blank" style="text-decoration: none; color: #6366f1; font-weight: 500;">Built with anycoder</a>
|
| 44 |
+
</div>
|
| 45 |
+
"""
|
| 46 |
+
)
|
| 47 |
+
|
| 48 |
+
with gr.Row(equal_height=True):
|
| 49 |
+
# Sidebar for Controls
|
| 50 |
+
with gr.Column(scale=1, min_width=300):
|
| 51 |
+
gr.Markdown("### ⚙️ Settings")
|
| 52 |
+
|
| 53 |
+
with gr.Accordion("Generation Parameters", open=True):
|
| 54 |
+
prompt_input = gr.Textbox(
|
| 55 |
+
label="Prompt",
|
| 56 |
+
placeholder="A futuristic city with flying cars at sunset, cinematic lighting, 4k...",
|
| 57 |
+
lines=3,
|
| 58 |
+
autofocus=True
|
| 59 |
+
)
|
| 60 |
+
|
| 61 |
+
negative_prompt_input = gr.Textbox(
|
| 62 |
+
label="Negative Prompt",
|
| 63 |
+
placeholder="blurry, low quality, distorted...",
|
| 64 |
+
lines=2
|
| 65 |
+
)
|
| 66 |
+
|
| 67 |
+
duration_slider = gr.Slider(
|
| 68 |
+
minimum=1,
|
| 69 |
+
maximum=10,
|
| 70 |
+
value=4,
|
| 71 |
+
step=1,
|
| 72 |
+
label="Duration (seconds)",
|
| 73 |
+
info="Longer videos take more time to generate."
|
| 74 |
+
)
|
| 75 |
+
|
| 76 |
+
seed_input = gr.Number(
|
| 77 |
+
label="Seed",
|
| 78 |
+
value=42,
|
| 79 |
+
precision=0,
|
| 80 |
+
info="Random seed for reproducibility."
|
| 81 |
+
)
|
| 82 |
+
|
| 83 |
+
random_seed_btn = gr.Button("🎲 Randomize Seed", size="sm")
|
| 84 |
+
|
| 85 |
+
with gr.Row():
|
| 86 |
+
generate_btn = gr.Button("🚀 Generate Video", variant="primary", scale=2)
|
| 87 |
+
clear_btn = gr.ClearButton([prompt_input, negative_prompt_input], scale=1)
|
| 88 |
+
|
| 89 |
+
gr.Markdown(
|
| 90 |
+
"""
|
| 91 |
+
<div style="font-size: 0.8em; color: #666; margin-top: 10px;">
|
| 92 |
+
*Note: This is a UI demo. The video generation is simulated.
|
| 93 |
+
</div>
|
| 94 |
+
"""
|
| 95 |
+
)
|
| 96 |
+
|
| 97 |
+
# Main Area for Output
|
| 98 |
+
with gr.Column(scale=2):
|
| 99 |
+
gr.Markdown("### 📺 Output")
|
| 100 |
+
|
| 101 |
+
video_output = gr.Video(
|
| 102 |
+
label="Generated Result",
|
| 103 |
+
autoplay=True,
|
| 104 |
+
show_download_button=True
|
| 105 |
+
)
|
| 106 |
+
|
| 107 |
+
status_output = gr.Textbox(
|
| 108 |
+
label="Status",
|
| 109 |
+
interactive=False,
|
| 110 |
+
show_label=False
|
| 111 |
+
)
|
| 112 |
+
|
| 113 |
+
# Examples Section
|
| 114 |
+
gr.Examples(
|
| 115 |
+
examples=[
|
| 116 |
+
["A majestic lion roaming the savanna, golden hour lighting", "blurry, cartoon", 4, 12345],
|
| 117 |
+
["Cyberpunk street with neon rain reflections, 8k resolution", "daylight, low quality", 5, 98765],
|
| 118 |
+
["Astronaut walking on Mars, cinematic shot, dust particles", "earth, studio", 3, 55555],
|
| 119 |
+
],
|
| 120 |
+
inputs=[prompt_input, negative_prompt_input, duration_slider, seed_input],
|
| 121 |
+
cache_examples=False, # Set to True if you want to pre-compute examples
|
| 122 |
+
label="Try these examples:"
|
| 123 |
+
)
|
| 124 |
+
|
| 125 |
+
# Event Listeners
|
| 126 |
+
|
| 127 |
+
# Generate Button Click
|
| 128 |
+
generate_btn.click(
|
| 129 |
+
fn=generate_video_mock,
|
| 130 |
+
inputs=[prompt_input, negative_prompt_input, duration_slider, seed_input],
|
| 131 |
+
outputs=[video_output, status_output],
|
| 132 |
+
api_visibility="public"
|
| 133 |
+
)
|
| 134 |
+
|
| 135 |
+
# Random Seed Button Click
|
| 136 |
+
random_seed_btn.click(
|
| 137 |
+
fn=update_seed,
|
| 138 |
+
inputs=[],
|
| 139 |
+
outputs=[seed_input],
|
| 140 |
+
api_visibility="private"
|
| 141 |
+
)
|
| 142 |
+
|
| 143 |
+
# Launch the App with Gradio 6 Syntax
|
| 144 |
+
# All theme, css, and footer parameters go here, NOT in gr.Blocks()
|
| 145 |
+
demo.launch(
|
| 146 |
+
theme=gr.themes.Soft(
|
| 147 |
+
primary_hue="indigo",
|
| 148 |
+
secondary_hue="purple",
|
| 149 |
+
neutral_hue="slate",
|
| 150 |
+
font=gr.themes.GoogleFont("Inter"),
|
| 151 |
+
text_size="lg",
|
| 152 |
+
spacing_size="lg",
|
| 153 |
+
radius_size="md"
|
| 154 |
+
).set(
|
| 155 |
+
button_primary_background_fill="*primary_500",
|
| 156 |
+
button_primary_background_fill_hover="*primary_600",
|
| 157 |
+
button_primary_text_color="white",
|
| 158 |
+
block_background_fill="*background_primary",
|
| 159 |
+
block_border_width="0px",
|
| 160 |
+
block_shadow="0 1px 2px 0 rgb(0 0 0 / 0.05)",
|
| 161 |
+
),
|
| 162 |
+
css="""
|
| 163 |
+
.gradio-container {
|
| 164 |
+
max-width: 1200px !important;
|
| 165 |
+
margin: auto !important;
|
| 166 |
+
}
|
| 167 |
+
""",
|
| 168 |
+
footer_links=[
|
| 169 |
+
{"label": "Gradio", "url": "https://gradio.app"},
|
| 170 |
+
{"label": "GitHub", "url": "https://github.com/gradio-app/gradio"},
|
| 171 |
+
{"label": "Built with anycoder", "url": "https://huggingface.co/spaces/akhaliq/anycoder"}
|
| 172 |
+
]
|
| 173 |
+
)
|
requirements.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
gradio
|