Update app.py
Browse files
app.py
CHANGED
|
@@ -20,7 +20,6 @@ try:
|
|
| 20 |
MOVIEPY_AVAILABLE = True
|
| 21 |
except ImportError:
|
| 22 |
MOVIEPY_AVAILABLE = False
|
| 23 |
-
st.warning("MoviePy not available. Video preview feature will be limited.")
|
| 24 |
|
| 25 |
# Configure page
|
| 26 |
st.set_page_config(
|
|
@@ -37,28 +36,29 @@ if 'storyboard_images' not in st.session_state:
|
|
| 37 |
if 'video_preview' not in st.session_state:
|
| 38 |
st.session_state.video_preview = None
|
| 39 |
|
| 40 |
-
#
|
| 41 |
-
|
| 42 |
-
gemini_api_key = st.
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
help="Get your API key from Google AI Studio"
|
| 47 |
-
)
|
| 48 |
-
hf_token = st.sidebar.text_input(
|
| 49 |
-
"Hugging Face Token",
|
| 50 |
-
value=os.getenv("HF_TOKEN", ""),
|
| 51 |
-
type="password",
|
| 52 |
-
help="Get your token from Hugging Face"
|
| 53 |
-
)
|
| 54 |
-
|
| 55 |
-
if gemini_api_key:
|
| 56 |
genai.configure(api_key=gemini_api_key)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
|
| 58 |
# Main title
|
| 59 |
st.title("🎬 AI Video Script & Storyboard Generator")
|
| 60 |
st.markdown("Create professional video scripts and visual storyboards with AI assistance")
|
| 61 |
|
|
|
|
|
|
|
|
|
|
| 62 |
# Input section
|
| 63 |
st.header("📝 Video Specifications")
|
| 64 |
|
|
@@ -104,10 +104,6 @@ with col2:
|
|
| 104 |
# Functions for AI generation
|
| 105 |
def generate_script_with_gemini(topic, length, style, tone, platform):
|
| 106 |
"""Generate video script using Gemini API"""
|
| 107 |
-
if not gemini_api_key:
|
| 108 |
-
st.error("Please provide Gemini API key in the sidebar")
|
| 109 |
-
return None
|
| 110 |
-
|
| 111 |
try:
|
| 112 |
model = genai.GenerativeModel('gemini-pro')
|
| 113 |
|
|
@@ -160,12 +156,8 @@ def generate_script_with_gemini(topic, length, style, tone, platform):
|
|
| 160 |
st.error(f"Error generating script: {str(e)}")
|
| 161 |
return None
|
| 162 |
|
| 163 |
-
def generate_storyboard_image(scene_description, art_style
|
| 164 |
"""Generate storyboard image using Stable Diffusion"""
|
| 165 |
-
if not hf_token:
|
| 166 |
-
st.error("Please provide Hugging Face token")
|
| 167 |
-
return None
|
| 168 |
-
|
| 169 |
try:
|
| 170 |
# Use Hugging Face Inference API for image generation
|
| 171 |
client = InferenceClient(token=hf_token)
|
|
@@ -295,10 +287,6 @@ def text_to_speech(text, language='en'):
|
|
| 295 |
if st.button("🚀 Generate Video Script & Storyboard", type="primary"):
|
| 296 |
if not video_topic:
|
| 297 |
st.error("Please enter a video topic")
|
| 298 |
-
elif not gemini_api_key:
|
| 299 |
-
st.error("Please provide Gemini API key")
|
| 300 |
-
elif not hf_token:
|
| 301 |
-
st.error("Please provide Hugging Face token")
|
| 302 |
else:
|
| 303 |
with st.spinner("🤖 Generating script with AI..."):
|
| 304 |
script_data = generate_script_with_gemini(video_topic, video_length, style, tone, platform)
|
|
@@ -315,8 +303,7 @@ if st.button("🚀 Generate Video Script & Storyboard", type="primary"):
|
|
| 315 |
for i, scene in enumerate(script_data['scenes']):
|
| 316 |
image = generate_storyboard_image(
|
| 317 |
scene['description'],
|
| 318 |
-
art_style
|
| 319 |
-
hf_token
|
| 320 |
)
|
| 321 |
images.append(image)
|
| 322 |
progress_bar.progress((i + 1) / len(script_data['scenes']))
|
|
@@ -376,8 +363,7 @@ if st.session_state.generated_script:
|
|
| 376 |
with st.spinner(f"Regenerating scene {i+1}..."):
|
| 377 |
new_image = generate_storyboard_image(
|
| 378 |
scene['description'],
|
| 379 |
-
art_style
|
| 380 |
-
hf_token
|
| 381 |
)
|
| 382 |
if new_image:
|
| 383 |
st.session_state.storyboard_images[i] = new_image
|
|
@@ -407,7 +393,7 @@ if st.session_state.generated_script:
|
|
| 407 |
st.session_state.video_preview = video_path
|
| 408 |
st.success("Video preview created!")
|
| 409 |
else:
|
| 410 |
-
st.info("Video preview requires MoviePy.
|
| 411 |
|
| 412 |
with col2:
|
| 413 |
if st.button("📱 Create GIF Preview"):
|
|
@@ -497,19 +483,23 @@ with st.sidebar:
|
|
| 497 |
st.markdown("---")
|
| 498 |
st.markdown("### 📚 How to Use")
|
| 499 |
st.markdown("""
|
| 500 |
-
1. **
|
| 501 |
-
2. **
|
| 502 |
-
3. **
|
| 503 |
-
4. **
|
| 504 |
-
5. **Export**: Download script, images, or video
|
| 505 |
""")
|
| 506 |
|
| 507 |
-
st.markdown("
|
| 508 |
-
st.markdown("
|
| 509 |
-
st.markdown("
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 510 |
|
| 511 |
if not MOVIEPY_AVAILABLE:
|
| 512 |
st.markdown("---")
|
| 513 |
-
st.markdown("###
|
| 514 |
-
st.markdown("
|
| 515 |
-
st.code("pip install moviepy")
|
|
|
|
| 20 |
MOVIEPY_AVAILABLE = True
|
| 21 |
except ImportError:
|
| 22 |
MOVIEPY_AVAILABLE = False
|
|
|
|
| 23 |
|
| 24 |
# Configure page
|
| 25 |
st.set_page_config(
|
|
|
|
| 36 |
if 'video_preview' not in st.session_state:
|
| 37 |
st.session_state.video_preview = None
|
| 38 |
|
| 39 |
+
# API Configuration from secrets
|
| 40 |
+
try:
|
| 41 |
+
gemini_api_key = st.secrets["GEMINI_API_KEY"]
|
| 42 |
+
hf_token = st.secrets["HF_TOKEN"]
|
| 43 |
+
|
| 44 |
+
# Configure Gemini API
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
genai.configure(api_key=gemini_api_key)
|
| 46 |
+
|
| 47 |
+
# Show success message in sidebar
|
| 48 |
+
st.sidebar.success("✅ API Keys loaded successfully!")
|
| 49 |
+
|
| 50 |
+
except Exception as e:
|
| 51 |
+
st.error("❌ API Keys not found in secrets. Please configure them in your deployment settings.")
|
| 52 |
+
st.info("Required secrets: GEMINI_API_KEY, HF_TOKEN")
|
| 53 |
+
st.stop()
|
| 54 |
|
| 55 |
# Main title
|
| 56 |
st.title("🎬 AI Video Script & Storyboard Generator")
|
| 57 |
st.markdown("Create professional video scripts and visual storyboards with AI assistance")
|
| 58 |
|
| 59 |
+
# Add information about the app
|
| 60 |
+
st.info("🔑 **API Keys are pre-configured** - Just enter your video details and generate!")
|
| 61 |
+
|
| 62 |
# Input section
|
| 63 |
st.header("📝 Video Specifications")
|
| 64 |
|
|
|
|
| 104 |
# Functions for AI generation
|
| 105 |
def generate_script_with_gemini(topic, length, style, tone, platform):
|
| 106 |
"""Generate video script using Gemini API"""
|
|
|
|
|
|
|
|
|
|
|
|
|
| 107 |
try:
|
| 108 |
model = genai.GenerativeModel('gemini-pro')
|
| 109 |
|
|
|
|
| 156 |
st.error(f"Error generating script: {str(e)}")
|
| 157 |
return None
|
| 158 |
|
| 159 |
+
def generate_storyboard_image(scene_description, art_style):
|
| 160 |
"""Generate storyboard image using Stable Diffusion"""
|
|
|
|
|
|
|
|
|
|
|
|
|
| 161 |
try:
|
| 162 |
# Use Hugging Face Inference API for image generation
|
| 163 |
client = InferenceClient(token=hf_token)
|
|
|
|
| 287 |
if st.button("🚀 Generate Video Script & Storyboard", type="primary"):
|
| 288 |
if not video_topic:
|
| 289 |
st.error("Please enter a video topic")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 290 |
else:
|
| 291 |
with st.spinner("🤖 Generating script with AI..."):
|
| 292 |
script_data = generate_script_with_gemini(video_topic, video_length, style, tone, platform)
|
|
|
|
| 303 |
for i, scene in enumerate(script_data['scenes']):
|
| 304 |
image = generate_storyboard_image(
|
| 305 |
scene['description'],
|
| 306 |
+
art_style
|
|
|
|
| 307 |
)
|
| 308 |
images.append(image)
|
| 309 |
progress_bar.progress((i + 1) / len(script_data['scenes']))
|
|
|
|
| 363 |
with st.spinner(f"Regenerating scene {i+1}..."):
|
| 364 |
new_image = generate_storyboard_image(
|
| 365 |
scene['description'],
|
| 366 |
+
art_style
|
|
|
|
| 367 |
)
|
| 368 |
if new_image:
|
| 369 |
st.session_state.storyboard_images[i] = new_image
|
|
|
|
| 393 |
st.session_state.video_preview = video_path
|
| 394 |
st.success("Video preview created!")
|
| 395 |
else:
|
| 396 |
+
st.info("Video preview requires MoviePy. Feature not available in this deployment.")
|
| 397 |
|
| 398 |
with col2:
|
| 399 |
if st.button("📱 Create GIF Preview"):
|
|
|
|
| 483 |
st.markdown("---")
|
| 484 |
st.markdown("### 📚 How to Use")
|
| 485 |
st.markdown("""
|
| 486 |
+
1. **Define Video**: Enter topic, length, and style
|
| 487 |
+
2. **Generate**: Click the generate button
|
| 488 |
+
3. **Refine**: Regenerate individual scenes if needed
|
| 489 |
+
4. **Export**: Download script, images, or video
|
|
|
|
| 490 |
""")
|
| 491 |
|
| 492 |
+
st.markdown("---")
|
| 493 |
+
st.markdown("### 🔧 Features")
|
| 494 |
+
st.markdown("""
|
| 495 |
+
- ✅ **AI Script Generation** with Gemini
|
| 496 |
+
- ✅ **Visual Storyboards** with Stable Diffusion
|
| 497 |
+
- ✅ **Text-to-Speech** for narration
|
| 498 |
+
- ✅ **Multiple Export Formats**
|
| 499 |
+
- ✅ **Scene Regeneration**
|
| 500 |
+
""")
|
| 501 |
|
| 502 |
if not MOVIEPY_AVAILABLE:
|
| 503 |
st.markdown("---")
|
| 504 |
+
st.markdown("### ℹ️ Note")
|
| 505 |
+
st.markdown("Video preview feature disabled for faster deployment. GIF preview available!")
|
|
|