Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -10,6 +10,21 @@ import numpy as np
|
|
| 10 |
from gtts import gTTS
|
| 11 |
import textwrap
|
| 12 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
class EnhancedVideoGenerator:
|
| 14 |
def __init__(self):
|
| 15 |
# Use device agnostic setup
|
|
@@ -44,7 +59,6 @@ class EnhancedVideoGenerator:
|
|
| 44 |
}
|
| 45 |
}
|
| 46 |
|
| 47 |
-
@st.cache_data
|
| 48 |
def generate_script(self, prompt, style, length):
|
| 49 |
"""Generate engaging script based on style and length"""
|
| 50 |
style_prompts = {
|
|
@@ -55,6 +69,7 @@ class EnhancedVideoGenerator:
|
|
| 55 |
|
| 56 |
max_length = int(length * 2.5) # Approximate words needed for duration
|
| 57 |
|
|
|
|
| 58 |
output = self.text_generator(
|
| 59 |
f"{style_prompts[style]} {prompt}. Keep it concise and engaging.",
|
| 60 |
max_length=max_length,
|
|
@@ -62,10 +77,8 @@ class EnhancedVideoGenerator:
|
|
| 62 |
temperature=0.7
|
| 63 |
)
|
| 64 |
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
script = script.replace(style_prompts[style], '').strip()
|
| 68 |
-
return script
|
| 69 |
|
| 70 |
def create_styled_frame(self, text, theme, frame_number, total_frames):
|
| 71 |
"""Create a visually appealing frame with text and progress bar"""
|
|
|
|
| 10 |
from gtts import gTTS
|
| 11 |
import textwrap
|
| 12 |
|
| 13 |
+
# Move the script generation to a standalone cached function
|
| 14 |
+
@st.cache_data
|
| 15 |
+
def generate_script_cached(prompt, style, length, model_output):
|
| 16 |
+
"""Cached version of script generation"""
|
| 17 |
+
style_prompts = {
|
| 18 |
+
'Professional': "Write a clear, professional script about:",
|
| 19 |
+
'Creative': "Write an engaging, creative script about:",
|
| 20 |
+
'Educational': "Write an informative educational script about:"
|
| 21 |
+
}
|
| 22 |
+
|
| 23 |
+
# Clean up the generated text
|
| 24 |
+
script = model_output[0]['generated_text']
|
| 25 |
+
script = script.replace(style_prompts[style], '').strip()
|
| 26 |
+
return script
|
| 27 |
+
|
| 28 |
class EnhancedVideoGenerator:
|
| 29 |
def __init__(self):
|
| 30 |
# Use device agnostic setup
|
|
|
|
| 59 |
}
|
| 60 |
}
|
| 61 |
|
|
|
|
| 62 |
def generate_script(self, prompt, style, length):
|
| 63 |
"""Generate engaging script based on style and length"""
|
| 64 |
style_prompts = {
|
|
|
|
| 69 |
|
| 70 |
max_length = int(length * 2.5) # Approximate words needed for duration
|
| 71 |
|
| 72 |
+
# Generate the text
|
| 73 |
output = self.text_generator(
|
| 74 |
f"{style_prompts[style]} {prompt}. Keep it concise and engaging.",
|
| 75 |
max_length=max_length,
|
|
|
|
| 77 |
temperature=0.7
|
| 78 |
)
|
| 79 |
|
| 80 |
+
# Use the cached function to process the output
|
| 81 |
+
return generate_script_cached(prompt, style, length, output)
|
|
|
|
|
|
|
| 82 |
|
| 83 |
def create_styled_frame(self, text, theme, frame_number, total_frames):
|
| 84 |
"""Create a visually appealing frame with text and progress bar"""
|