| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| import gradio as gr |
| from model import Model |
| import os |
| from hf_utils import get_model_list |
|
|
| |
| on_huggingspace = os.environ.get("SPACE_ID") is not None |
|
|
| |
| |
| |
| |
| examples = [ |
| ["an astronaut waving the arm on the moon", "dreamlike-art/dreamlike-photoreal-2.0", 2], |
| ["a sloth surfing on a wakeboard", "dreamlike-art/dreamlike-photoreal-2.0", 2], |
| ["an astronaut walking on a street", "dreamlike-art/dreamlike-photoreal-2.0", 2], |
| ["a cute cat walking on grass", "dreamlike-art/dreamlike-photoreal-2.0", 2], |
| ["a horse is galloping on a street", "dreamlike-art/dreamlike-photoreal-2.0", 2], |
| ["an astronaut is skiing down the hill", "dreamlike-art/dreamlike-photoreal-2.0", 2], |
| ["a gorilla walking alone down the street", "dreamlike-art/dreamlike-photoreal-2.0", 2], |
| ["a gorilla dancing on times square", "dreamlike-art/dreamlike-photoreal-2.0", 2], |
| ["A panda dancing dancing like crazy on Times Square", "dreamlike-art/dreamlike-photoreal-2.0", 2], |
| ] |
|
|
|
|
| def create_demo(model: Model): |
| """ |
| Constructs and returns the interactive elements of the Gradio interface for textual inputs. |
| Binds the local inference 'model' context to user-facing input handlers to coordinate state |
| between the UI framework and the PyTorch execution context. |
| """ |
| import torch |
| is_cpu = not torch.cuda.is_available() |
|
|
| |
| |
| |
| def generate_video(prompt, model_name, video_length): |
| return model.process_text2video( |
| prompt=prompt, |
| model_name=model_name, |
| video_length=int(video_length), |
| ) |
|
|
| |
| with gr.Blocks() as demo: |
| with gr.Row(): |
| gr.HTML( |
| """ |
| <div style="background: rgba(142,45,226,0.1); padding: 1.5rem; border-left: 5px solid #8E2DE2; border-radius: 10px; margin-bottom: 1.5rem; display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 1rem;"> |
| <div style="flex: 1; min-width: 300px;"> |
| <h2 style="font-weight: 700; font-size: 1.6rem; margin: 0; color: #4A00E0;"> |
| Zero-Shot Video Studio |
| </h2> |
| <p style="margin-top: 0.5rem; color: #555; font-size: 1rem; font-weight: 500; line-height: 1.4;"> |
| Transform cinematic text prompts into dynamic, temporally consistent AI video. Choose a diffusion model, describe your vision, and generate instantly. |
| </p> |
| </div> |
| <a href="https://colab.research.google.com/github/Amey-Thakur/ZERO-SHOT-VIDEO-GENERATION/blob/main/ZERO-SHOT-VIDEO-GENERATION.ipynb" target="_blank" style="text-decoration: none; transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1); display: inline-flex; align-items: center; background: white; padding: 0.7rem 1.2rem; border-radius: 12px; border: 1px solid rgba(142,45,226,0.15); box-shadow: 0 4px 15px rgba(0,0,0,0.05);"> |
| <div style="display: flex; flex-direction: column; align-items: flex-start; margin-right: 1rem;"> |
| <span style="font-size: 0.7rem; font-weight: 800; color: #8E2DE2; text-transform: uppercase; letter-spacing: 1px; margin-bottom: 2px;">Neural Architecture</span> |
| <span style="font-size: 0.95rem; font-weight: 600; color: #4A00E0;">Verified Research Notebook</span> |
| </div> |
| <img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Colab" style="height: 22px;"/> |
| </a> |
| </div> |
| """ |
| ) |
|
|
| if is_cpu: |
| gr.HTML( |
| """ |
| <div style="background: rgba(255,165,0,0.1); padding: 1rem; border-left: 4px solid #FFA500; border-radius: 8px; margin-bottom: 1rem;"> |
| <p style="margin: 0; color: #856404; font-size: 0.9rem; line-height: 1.6;"> |
| <strong>β‘ CPU Mode.</strong> Running on free-tier hardware. Resolution and frames are reduced to fit this environment. |
| Full resolution on T4 GPU works on Google Colab. Click the notebook link above to try it. |
| </p> |
| </div> |
| """ |
| ) |
|
|
| with gr.Row(equal_height=False): |
| with gr.Column(scale=1, variant="panel"): |
| gr.Markdown("### β¨ Model & Concept Configuration") |
| |
| model_name = gr.Dropdown( |
| label="Diffusion Strategy (Model)", |
| choices=get_model_list(), |
| value="dreamlike-art/dreamlike-photoreal-2.0", |
| ) |
| prompt = gr.Textbox( |
| label='Cinematic Prompt', |
| placeholder="Describe the scene in detail (e.g. 'an astronaut waving the arm on the moon')...", |
| lines=3 |
| ) |
| run_button = gr.Button(value='Generate Sequence π¬', variant='primary', size="lg") |
| |
| |
| with gr.Accordion('π οΈ Advanced Options', open=False): |
| |
| |
| if is_cpu: |
| video_length = gr.Slider( |
| label="Video Timeline (Frames)", minimum=2, maximum=4, step=1, value=2) |
| elif on_huggingspace: |
| video_length = gr.Slider( |
| label="Video Timeline (Frames)", minimum=8, maximum=16, step=1, value=8) |
| else: |
| video_length = gr.Number( |
| label="Video Timeline (Frames)", value=8, precision=0) |
|
|
| with gr.Column(scale=1): |
| |
| gr.Markdown("### ποΈ Output Stream") |
| result = gr.Video(label="Synthesized Video Result", height=380) |
|
|
| inputs = [ |
| prompt, |
| model_name, |
| video_length, |
| ] |
|
|
| |
| |
| |
| gr.Examples(examples=examples, |
| inputs=inputs, |
| outputs=result, |
| fn=generate_video, |
| run_on_click=False, |
| cache_examples=False, |
| ) |
|
|
| |
| run_button.click(fn=generate_video, |
| inputs=inputs, |
| outputs=result,) |
| return demo |
|
|