Spaces:
Runtime error
Runtime error
# 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 |