Pravin Barapatre
Fix: Always return dict for gr.JSON model_info to avoid gradio_client TypeError
7bd9a2d
import gradio as gr
import logging
import tempfile
import os
# Set up logging
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
def create_interface():
"""Create the Gradio interface"""
def generate_video_interface(prompt, model_id, num_frames, fps, num_inference_steps, guidance_scale, seed):
"""Interface function for video generation"""
if not prompt.strip():
return None, "Please enter a video description"
# For demo purposes, return a message instead of actual video generation
# This will work on Hugging Face Spaces without NumPy issues
return None, f"Demo mode: Would generate video for '{prompt}' using {model_id} with {num_frames} frames at {fps} FPS"
# Custom CSS for better styling
custom_css = """
.gradio-container {
max-width: 1200px !important;
margin: 0 auto !important;
}
.generate-btn {
background: linear-gradient(45deg, #667eea 0%, #764ba2 100%) !important;
border: none !important;
color: white !important;
font-weight: bold !important;
}
.status-box {
background-color: #f8f9fa !important;
border: 1px solid #dee2e6 !important;
}
"""
# Available models for demo
models = {
"damo-vilab/text-to-video-ms-1.7b": {
"name": "DAMO Text-to-Video MS-1.7B",
"description": "Fast and efficient text-to-video model",
"max_frames": 16,
"fps": 8,
"quality": "Good",
"speed": "Fast"
},
"cerspense/zeroscope_v2_XL": {
"name": "Zeroscope v2 XL",
"description": "High-quality text-to-video model",
"max_frames": 24,
"fps": 6,
"quality": "Excellent",
"speed": "Medium"
}
}
# Create interface
with gr.Blocks(title="AI Video Creator Pro", theme=gr.themes.Soft(), css=custom_css) as interface:
# Professional Header
with gr.Group():
gr.Markdown("""
# 🎬 AI Video Creator Pro
### Transform Your Ideas Into Stunning Videos with AI-Powered Generation
""")
with gr.Row():
with gr.Column(scale=2):
# Main Input Section
with gr.Group():
gr.Markdown("## 🎯 Video Generation")
prompt = gr.Textbox(
label="πŸ“ Video Description",
placeholder="Describe the video you want to create... (e.g., 'A majestic dragon soaring through a mystical forest with glowing mushrooms')",
lines=3,
max_lines=5,
container=True
)
model_id = gr.Dropdown(
choices=list(models.keys()),
value=list(models.keys())[0],
label="πŸ€– AI Model",
info="Choose the AI model for video generation",
container=True
)
with gr.Row():
num_frames = gr.Slider(
minimum=8,
maximum=32,
value=16,
step=1,
label="🎞️ Video Length (Frames)",
info="More frames = longer video"
)
fps = gr.Slider(
minimum=4,
maximum=12,
value=8,
step=1,
label="⚑ FPS",
info="Frames per second"
)
with gr.Row():
num_inference_steps = gr.Slider(
minimum=10,
maximum=50,
value=25,
step=1,
label="🎨 Quality Steps",
info="More steps = better quality but slower"
)
guidance_scale = gr.Slider(
minimum=1.0,
maximum=20.0,
value=7.5,
step=0.5,
label="🎯 Guidance Scale",
info="Higher values = more prompt adherence"
)
seed = gr.Number(
label="🎲 Seed (Optional)",
value=None,
info="Set for reproducible results",
container=True
)
# Generate Button
generate_btn = gr.Button("πŸš€ Generate Professional Video", variant="primary", size="lg")
# Output Section
with gr.Group():
gr.Markdown("## πŸ“Ί Generated Video")
status_text = gr.Textbox(label="πŸ“Š Status", interactive=False)
video_output = gr.Video(label="🎬 Your Video")
with gr.Column(scale=1):
# Model Information
with gr.Group():
gr.Markdown("## πŸ€– AI Model Details")
model_info = gr.JSON(label="Current Model Specifications")
# Examples
with gr.Group():
gr.Markdown("## πŸ’‘ Inspiration Examples")
gr.Markdown("""
**Try these example prompts:**
β€’ A beautiful sunset over the ocean with waves crashing on the shore
β€’ A cat playing with a ball of yarn in a cozy living room
β€’ A futuristic city with flying cars and neon lights
β€’ A butterfly emerging from a cocoon in a garden
β€’ A rocket launching into space with fire and smoke
β€’ A majestic dragon soaring through a mystical forest with glowing mushrooms
""")
# Features
with gr.Group():
gr.Markdown("## ✨ Features")
gr.Markdown("""
🎬 **Multiple AI Models**
- State-of-the-art video generation
- Quality vs speed options
🎨 **Advanced Controls**
- Quality settings
- Reproducible results
⚑ **Fast Processing**
- GPU acceleration
- Optimized pipelines
""")
# Event handlers
generate_btn.click(
fn=generate_video_interface,
inputs=[prompt, model_id, num_frames, fps, num_inference_steps, guidance_scale, seed],
outputs=[video_output, status_text]
)
# Update model info when model changes
def update_model_info(model_id):
info = models.get(model_id, {"error": "Model not found"})
if not isinstance(info, dict):
info = {"error": "Invalid model info"}
return info
model_id.change(
fn=update_model_info,
inputs=model_id,
outputs=model_info
)
# Load initial model info
interface.load(lambda: models[list(models.keys())[0]], outputs=model_info)
return interface
# Create and launch the interface
interface = create_interface()
interface.launch(
server_name="0.0.0.0",
server_port=7860,
share=True,
show_error=True
)