Delete app7.py
Browse files
app7.py
DELETED
|
@@ -1,146 +0,0 @@
|
|
| 1 |
-
import gradio as gr
|
| 2 |
-
import requests
|
| 3 |
-
import os
|
| 4 |
-
import time
|
| 5 |
-
import logging
|
| 6 |
-
from PIL import Image
|
| 7 |
-
import io
|
| 8 |
-
|
| 9 |
-
# Set up logging
|
| 10 |
-
logging.basicConfig(level=logging.INFO)
|
| 11 |
-
logger = logging.getLogger(__name__)
|
| 12 |
-
|
| 13 |
-
# Get API key (match your secret name - 'key' or 'Key')
|
| 14 |
-
API_KEY = os.environ.get("key", os.environ.get("Key", ""))
|
| 15 |
-
if not API_KEY:
|
| 16 |
-
logger.error("❌ No API key found")
|
| 17 |
-
|
| 18 |
-
def upload_to_temp_url(image):
|
| 19 |
-
"""Upload image to temporary hosting and return URL"""
|
| 20 |
-
# For now, we'll need a temporary hosting solution
|
| 21 |
-
# Option 1: Use imgbb.com API (need another key)
|
| 22 |
-
# Option 2: Use Hugging Face's temp files (but need public URL)
|
| 23 |
-
# Option 3: Keep URL input for now until we set up hosting
|
| 24 |
-
|
| 25 |
-
# For simplicity now, we'll keep URL input
|
| 26 |
-
# But we can add image preview
|
| 27 |
-
return None
|
| 28 |
-
|
| 29 |
-
def generate_video(image, prompt_text, model_id, progress=gr.Progress()):
|
| 30 |
-
"""Generate video using image upload and prompt"""
|
| 31 |
-
|
| 32 |
-
if not API_KEY:
|
| 33 |
-
yield "❌ API key not configured", None
|
| 34 |
-
return
|
| 35 |
-
|
| 36 |
-
try:
|
| 37 |
-
progress(0, desc="Preparing request...")
|
| 38 |
-
|
| 39 |
-
# For now, we need a publicly accessible image URL
|
| 40 |
-
# This is a limitation - we need to host the uploaded image somewhere
|
| 41 |
-
# Let's use a placeholder message until we implement hosting
|
| 42 |
-
if image is None:
|
| 43 |
-
yield "⚠️ Please upload an image", None
|
| 44 |
-
return
|
| 45 |
-
|
| 46 |
-
# For demo purposes, we'll keep URL input for now
|
| 47 |
-
# But we show the uploaded image preview
|
| 48 |
-
yield "⏳ Image uploaded. For now, please also provide a public URL (hosting service needed)", None
|
| 49 |
-
return
|
| 50 |
-
|
| 51 |
-
# The actual API call would go here once we have URL hosting
|
| 52 |
-
|
| 53 |
-
except Exception as e:
|
| 54 |
-
logger.error(f"❌ Error: {str(e)}")
|
| 55 |
-
yield f"❌ Error: {str(e)}", None
|
| 56 |
-
|
| 57 |
-
# Simple, clean interface
|
| 58 |
-
with gr.Blocks(title="BytePlus Video Generator", theme=gr.themes.Soft()) as demo:
|
| 59 |
-
|
| 60 |
-
gr.Markdown("""
|
| 61 |
-
# 🎥 BytePlus Video Generator
|
| 62 |
-
Upload an image and describe the video you want to generate
|
| 63 |
-
""")
|
| 64 |
-
|
| 65 |
-
with gr.Row():
|
| 66 |
-
with gr.Column():
|
| 67 |
-
# Image upload (input only)
|
| 68 |
-
image_input = gr.Image(
|
| 69 |
-
label="📤 Upload Starting Image",
|
| 70 |
-
type="pil",
|
| 71 |
-
height=300
|
| 72 |
-
)
|
| 73 |
-
|
| 74 |
-
# Text prompt
|
| 75 |
-
prompt = gr.Textbox(
|
| 76 |
-
label="📝 Video Description",
|
| 77 |
-
placeholder="Describe what you want to see...",
|
| 78 |
-
lines=3,
|
| 79 |
-
value="At breakneck speed, drones thread through intricate obstacles --duration 5 --camerafixed false"
|
| 80 |
-
)
|
| 81 |
-
|
| 82 |
-
# Model ID (hidden or simplified)
|
| 83 |
-
model_id = gr.Textbox(
|
| 84 |
-
label="Model ID",
|
| 85 |
-
value="seedance-1-5-pro-251215",
|
| 86 |
-
visible=False # Hide it for simplicity
|
| 87 |
-
)
|
| 88 |
-
|
| 89 |
-
# Generate button
|
| 90 |
-
generate_btn = gr.Button("🚀 Generate Video", variant="primary", size="lg")
|
| 91 |
-
|
| 92 |
-
with gr.Column():
|
| 93 |
-
# Status messages
|
| 94 |
-
status = gr.Textbox(
|
| 95 |
-
label="Status",
|
| 96 |
-
lines=2,
|
| 97 |
-
interactive=False
|
| 98 |
-
)
|
| 99 |
-
|
| 100 |
-
# Video output (player only, not uploader)
|
| 101 |
-
video_output = gr.Video(
|
| 102 |
-
label="🎬 Generated Video",
|
| 103 |
-
interactive=False, # Can't upload, only view
|
| 104 |
-
show_download_button=True, # Allow download
|
| 105 |
-
height=300
|
| 106 |
-
)
|
| 107 |
-
|
| 108 |
-
# Example prompts (optional)
|
| 109 |
-
gr.Markdown("---")
|
| 110 |
-
gr.Markdown("### Example Prompts")
|
| 111 |
-
with gr.Row():
|
| 112 |
-
gr.Button("Nature Drone").click(
|
| 113 |
-
fn=lambda: "Aerial drone shot over mountains at sunrise, cinematic --duration 5 --camerafixed false",
|
| 114 |
-
outputs=prompt
|
| 115 |
-
)
|
| 116 |
-
gr.Button("City Race").click(
|
| 117 |
-
fn=lambda: "Fast drone racing through futuristic city streets --duration 5 --camerafixed false",
|
| 118 |
-
outputs=prompt
|
| 119 |
-
)
|
| 120 |
-
gr.Button("Ocean Waves").click(
|
| 121 |
-
fn=lambda: "Drone following waves at golden hour --duration 5 --camerafixed false",
|
| 122 |
-
outputs=prompt
|
| 123 |
-
)
|
| 124 |
-
|
| 125 |
-
# For now, show a note about image hosting
|
| 126 |
-
gr.Markdown("""
|
| 127 |
-
---
|
| 128 |
-
⚠️ **Note:** Currently requires publicly accessible image URLs.
|
| 129 |
-
Working on direct image upload support!
|
| 130 |
-
""")
|
| 131 |
-
|
| 132 |
-
# Placeholder function for now
|
| 133 |
-
def placeholder_gen(image, prompt, model):
|
| 134 |
-
if image is None:
|
| 135 |
-
return "Please upload an image first", None
|
| 136 |
-
return "Image uploaded! (URL hosting coming soon)", None
|
| 137 |
-
|
| 138 |
-
# Connect the button
|
| 139 |
-
generate_btn.click(
|
| 140 |
-
fn=placeholder_gen,
|
| 141 |
-
inputs=[image_input, prompt, model_id],
|
| 142 |
-
outputs=[status, video_output]
|
| 143 |
-
)
|
| 144 |
-
|
| 145 |
-
if __name__ == "__main__":
|
| 146 |
-
demo.launch(server_name="0.0.0.0")
|
|
|
|
|
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