Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -44,8 +44,14 @@ class ProfessionalCartoonFilmGenerator:
|
|
| 44 |
|
| 45 |
# Use a persistent directory for Hugging Face Spaces
|
| 46 |
# Files here can be served by Gradio
|
| 47 |
-
self.
|
| 48 |
-
os.makedirs(self.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
|
| 50 |
# Model configurations for ZeroGPU optimization
|
| 51 |
self.models_loaded = False
|
|
@@ -561,7 +567,7 @@ class ProfessionalCartoonFilmGenerator:
|
|
| 561 |
else:
|
| 562 |
raise e
|
| 563 |
|
| 564 |
-
char_path = f"{self.
|
| 565 |
image.save(char_path)
|
| 566 |
character_images[character['name']] = char_path
|
| 567 |
|
|
@@ -659,7 +665,7 @@ class ProfessionalCartoonFilmGenerator:
|
|
| 659 |
else:
|
| 660 |
raise e
|
| 661 |
|
| 662 |
-
bg_path = f"{self.
|
| 663 |
image.save(bg_path)
|
| 664 |
background_images[scene['scene_number']] = bg_path
|
| 665 |
|
|
@@ -798,7 +804,7 @@ class ProfessionalCartoonFilmGenerator:
|
|
| 798 |
# Use the optimization function to ensure CLIP compatibility
|
| 799 |
prompt = self.optimize_prompt_for_clip(prompt)
|
| 800 |
|
| 801 |
-
video_path = f"{self.
|
| 802 |
|
| 803 |
# Get the correct Open-Sora directory
|
| 804 |
current_dir = os.getcwd()
|
|
@@ -813,7 +819,7 @@ class ProfessionalCartoonFilmGenerator:
|
|
| 813 |
"torchrun", "--nproc_per_node", "1", "--standalone",
|
| 814 |
"scripts/diffusion/inference.py",
|
| 815 |
"configs/diffusion/inference/t2i2v_256px.py",
|
| 816 |
-
"--save-dir", self.
|
| 817 |
"--prompt", prompt,
|
| 818 |
"--num_frames", "25", # ~1 second at 25fps
|
| 819 |
"--aspect_ratio", "4:3",
|
|
@@ -824,9 +830,9 @@ class ProfessionalCartoonFilmGenerator:
|
|
| 824 |
|
| 825 |
if result.returncode == 0:
|
| 826 |
# Find generated video file
|
| 827 |
-
for file in os.listdir(self.
|
| 828 |
if file.endswith('.mp4') and 'scene' not in file:
|
| 829 |
-
src_path = os.path.join(self.
|
| 830 |
os.rename(src_path, video_path)
|
| 831 |
return video_path
|
| 832 |
|
|
@@ -844,7 +850,7 @@ class ProfessionalCartoonFilmGenerator:
|
|
| 844 |
print(f"β No background image for scene {scene_num}")
|
| 845 |
return None
|
| 846 |
|
| 847 |
-
video_path = f"{self.
|
| 848 |
|
| 849 |
try:
|
| 850 |
print(f"π¬ Creating static video for scene {scene_num}...")
|
|
@@ -973,7 +979,7 @@ class ProfessionalCartoonFilmGenerator:
|
|
| 973 |
print(f"β No background image for scene {scene_num}")
|
| 974 |
return None
|
| 975 |
|
| 976 |
-
video_path = f"{self.
|
| 977 |
|
| 978 |
try:
|
| 979 |
print(f"π¬ Creating simple video for scene {scene_num}...")
|
|
@@ -1044,7 +1050,7 @@ class ProfessionalCartoonFilmGenerator:
|
|
| 1044 |
background_color = (100, 150, 200) # Blue-ish color
|
| 1045 |
|
| 1046 |
# Create video
|
| 1047 |
-
video_path = f"{self.
|
| 1048 |
fourcc = cv2.VideoWriter_fourcc(*'mp4v')
|
| 1049 |
fps = 24
|
| 1050 |
duration = 30 # 30 seconds
|
|
@@ -1095,13 +1101,13 @@ class ProfessionalCartoonFilmGenerator:
|
|
| 1095 |
print("β No videos to merge")
|
| 1096 |
return None
|
| 1097 |
|
| 1098 |
-
final_video_path = f"{self.
|
| 1099 |
|
| 1100 |
try:
|
| 1101 |
print("ποΈ Creating professional cartoon film...")
|
| 1102 |
|
| 1103 |
# Create concat file
|
| 1104 |
-
concat_file = f"{self.
|
| 1105 |
with open(concat_file, 'w') as f:
|
| 1106 |
for video in scene_videos:
|
| 1107 |
if os.path.exists(video):
|
|
|
|
| 44 |
|
| 45 |
# Use a persistent directory for Hugging Face Spaces
|
| 46 |
# Files here can be served by Gradio
|
| 47 |
+
self.output_dir = "./outputs"
|
| 48 |
+
os.makedirs(self.output_dir, exist_ok=True)
|
| 49 |
+
print(f"π Created output directory: {self.output_dir}")
|
| 50 |
+
|
| 51 |
+
# Also create subdirectories for organization
|
| 52 |
+
os.makedirs(os.path.join(self.output_dir, "characters"), exist_ok=True)
|
| 53 |
+
os.makedirs(os.path.join(self.output_dir, "backgrounds"), exist_ok=True)
|
| 54 |
+
os.makedirs(os.path.join(self.output_dir, "videos"), exist_ok=True)
|
| 55 |
|
| 56 |
# Model configurations for ZeroGPU optimization
|
| 57 |
self.models_loaded = False
|
|
|
|
| 567 |
else:
|
| 568 |
raise e
|
| 569 |
|
| 570 |
+
char_path = f"{self.output_dir}/characters/character_{character['name'].replace(' ', '_')}.png"
|
| 571 |
image.save(char_path)
|
| 572 |
character_images[character['name']] = char_path
|
| 573 |
|
|
|
|
| 665 |
else:
|
| 666 |
raise e
|
| 667 |
|
| 668 |
+
bg_path = f"{self.output_dir}/backgrounds/background_scene_{scene['scene_number']}.png"
|
| 669 |
image.save(bg_path)
|
| 670 |
background_images[scene['scene_number']] = bg_path
|
| 671 |
|
|
|
|
| 804 |
# Use the optimization function to ensure CLIP compatibility
|
| 805 |
prompt = self.optimize_prompt_for_clip(prompt)
|
| 806 |
|
| 807 |
+
video_path = f"{self.output_dir}/videos/scene_{scene['scene_number']}.mp4"
|
| 808 |
|
| 809 |
# Get the correct Open-Sora directory
|
| 810 |
current_dir = os.getcwd()
|
|
|
|
| 819 |
"torchrun", "--nproc_per_node", "1", "--standalone",
|
| 820 |
"scripts/diffusion/inference.py",
|
| 821 |
"configs/diffusion/inference/t2i2v_256px.py",
|
| 822 |
+
"--save-dir", self.output_dir,
|
| 823 |
"--prompt", prompt,
|
| 824 |
"--num_frames", "25", # ~1 second at 25fps
|
| 825 |
"--aspect_ratio", "4:3",
|
|
|
|
| 830 |
|
| 831 |
if result.returncode == 0:
|
| 832 |
# Find generated video file
|
| 833 |
+
for file in os.listdir(self.output_dir):
|
| 834 |
if file.endswith('.mp4') and 'scene' not in file:
|
| 835 |
+
src_path = os.path.join(self.output_dir, file)
|
| 836 |
os.rename(src_path, video_path)
|
| 837 |
return video_path
|
| 838 |
|
|
|
|
| 850 |
print(f"β No background image for scene {scene_num}")
|
| 851 |
return None
|
| 852 |
|
| 853 |
+
video_path = f"{self.output_dir}/videos/scene_{scene_num}.mp4"
|
| 854 |
|
| 855 |
try:
|
| 856 |
print(f"π¬ Creating static video for scene {scene_num}...")
|
|
|
|
| 979 |
print(f"β No background image for scene {scene_num}")
|
| 980 |
return None
|
| 981 |
|
| 982 |
+
video_path = f"{self.output_dir}/videos/simple_scene_{scene_num}.mp4"
|
| 983 |
|
| 984 |
try:
|
| 985 |
print(f"π¬ Creating simple video for scene {scene_num}...")
|
|
|
|
| 1050 |
background_color = (100, 150, 200) # Blue-ish color
|
| 1051 |
|
| 1052 |
# Create video
|
| 1053 |
+
video_path = f"{self.output_dir}/videos/emergency_fallback.mp4"
|
| 1054 |
fourcc = cv2.VideoWriter_fourcc(*'mp4v')
|
| 1055 |
fps = 24
|
| 1056 |
duration = 30 # 30 seconds
|
|
|
|
| 1101 |
print("β No videos to merge")
|
| 1102 |
return None
|
| 1103 |
|
| 1104 |
+
final_video_path = f"{self.output_dir}/videos/professional_cartoon_film.mp4"
|
| 1105 |
|
| 1106 |
try:
|
| 1107 |
print("ποΈ Creating professional cartoon film...")
|
| 1108 |
|
| 1109 |
# Create concat file
|
| 1110 |
+
concat_file = f"{self.output_dir}/videos/concat_list.txt"
|
| 1111 |
with open(concat_file, 'w') as f:
|
| 1112 |
for video in scene_videos:
|
| 1113 |
if os.path.exists(video):
|