Spaces:
Runtime error
Runtime error
File size: 2,761 Bytes
3fffcf9 d9486d1 86c6777 3fffcf9 25bd165 3fffcf9 929083d 3fffcf9 86c6777 25bd165 86c6777 3fffcf9 86c6777 3fffcf9 86c6777 d9486d1 3fffcf9 9719d16 3fffcf9 d9486d1 3fffcf9 a12cf12 3fffcf9 a12cf12 3fffcf9 d9486d1 3fffcf9 d9486d1 3fffcf9 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# app.py (Temporary script for direct testing)
import os
import sys
import subprocess
import re
import traceback
import time
# Add project root to Python path
sys.path.insert(0, os.getcwd())
# --- Download Kokoro models if they don't exist ---
model_dir = "models"
if not os.path.exists(os.path.join(model_dir, "kokoro-v0_19.onnx")):
print("Downloading Kokoro TTS models...")
os.makedirs(model_dir, exist_ok=True)
os.system(f"wget -P {model_dir} https://github.com/thewh1teagle/kokoro-onnx/releases/download/model-files/kokoro-v0_19.onnx")
os.system(f"wget -P {model_dir} https://github.com/thewh1teagle/kokoro-onnx/releases/download/model-files/voices.bin")
print("Model download complete.")
print("\n" + "="*50)
print("--- DIRECT EXECUTION TEST ---")
print("This script will now directly run 'generate_video.py'.")
print("Check the logs below for real-time output and the final error.")
print("="*50 + "\n")
sys.stdout.flush() # Ensures the above text is printed immediately
# --- Hardcoded Test Parameters ---
topic = "The Pythagorean Theorem"
context = "In a right-angled triangle, the square of the length of the hypotenuse is equal to the sum of the squares of the lengths of the other two sides."
model = "gemini/gemini-2.0-flash"
file_prefix = re.sub(r'[^a-z0-9_]+', '_', topic.lower())
output_dir = os.path.join("output", file_prefix)
# --- Construct the command ---
command = [
"python", "-u", "generate_video.py", # '-u' for unbuffered output
"--model", model,
"--topic", topic,
"--context", context,
"--output_dir", output_dir
]
print(f"Executing command: {' '.join(command)}\n")
sys.stdout.flush()
# --- Run the command and stream output ---
try:
process = subprocess.Popen(
command,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
text=True,
bufsize=1,
universal_newlines=True
)
# Read and print output line-by-line
for line in iter(process.stdout.readline, ''):
print(line, end='')
sys.stdout.flush()
process.wait() # Wait for the process to finish
if process.returncode == 0:
print("\n--- TEST SUCCEEDED ---")
print(f"Script finished with exit code 0. Check the 'Files' tab for the video in the '{output_dir}' directory.")
else:
print(f"\n--- TEST FAILED WITH EXIT CODE {process.returncode} ---")
print("The error traceback should be visible above.")
except Exception:
print(f"\n--- SCRIPT CRASHED WITH AN EXCEPTION ---")
print(traceback.format_exc())
print("\n--- DIRECT TEST SCRIPT FINISHED ---")
print("The Space will now idle. To run another test, you must restart the Space.")
time.sleep(3600) # Keep the container alive for an hour for you to check logs |