Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -21,9 +21,9 @@ def run_async(coro):
|
|
| 21 |
loop.close()
|
| 22 |
return result
|
| 23 |
|
| 24 |
-
# Load
|
| 25 |
try:
|
| 26 |
-
generator = pipeline("text-generation", model="
|
| 27 |
except Exception as e:
|
| 28 |
print(f"Error loading model: {e}")
|
| 29 |
generator = None
|
|
@@ -46,7 +46,7 @@ def generate_script(prompt, custom_text=None):
|
|
| 46 |
|
| 47 |
# Generate script with local model
|
| 48 |
if generator:
|
| 49 |
-
input_text = f"
|
| 50 |
try:
|
| 51 |
result = generator(input_text, max_length=300, num_return_sequences=1, do_sample=True)[0]['generated_text']
|
| 52 |
return result.strip()
|
|
@@ -129,7 +129,7 @@ def create_video(prompt, custom_text, music_file):
|
|
| 129 |
else:
|
| 130 |
final_clip = final_clip.set_audio(audio)
|
| 131 |
|
| 132 |
-
# Write final video
|
| 133 |
final_clip.write_videofile(output_video, codec="libx264", audio_codec="aac", fps=24)
|
| 134 |
|
| 135 |
# Clean up
|
|
|
|
| 21 |
loop.close()
|
| 22 |
return result
|
| 23 |
|
| 24 |
+
# Load lightweight text generation model
|
| 25 |
try:
|
| 26 |
+
generator = pipeline("text-generation", model="distilbert/distilgpt2", device="cpu")
|
| 27 |
except Exception as e:
|
| 28 |
print(f"Error loading model: {e}")
|
| 29 |
generator = None
|
|
|
|
| 46 |
|
| 47 |
# Generate script with local model
|
| 48 |
if generator:
|
| 49 |
+
input_text = f"Generate a script for a video about '{prompt}'. Create a numbered list with short descriptions (max 20 words per item) for a top 10 related to the topic."
|
| 50 |
try:
|
| 51 |
result = generator(input_text, max_length=300, num_return_sequences=1, do_sample=True)[0]['generated_text']
|
| 52 |
return result.strip()
|
|
|
|
| 129 |
else:
|
| 130 |
final_clip = final_clip.set_audio(audio)
|
| 131 |
|
| 132 |
+
# Write final video
|
| 133 |
final_clip.write_videofile(output_video, codec="libx264", audio_codec="aac", fps=24)
|
| 134 |
|
| 135 |
# Clean up
|