Update app.py
Browse files
app.py
CHANGED
@@ -42,16 +42,13 @@ class ProfessionalCartoonFilmGenerator:
|
|
42 |
def __init__(self):
|
43 |
self.device = "cuda" if torch.cuda.is_available() else "cpu"
|
44 |
|
45 |
-
# Use
|
46 |
-
#
|
47 |
-
self.output_dir = "
|
48 |
-
|
49 |
-
print(f"π Created output directory: {self.output_dir}")
|
50 |
|
51 |
-
#
|
52 |
-
|
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,7 +564,7 @@ class ProfessionalCartoonFilmGenerator:
|
|
567 |
else:
|
568 |
raise e
|
569 |
|
570 |
-
char_path = f"{self.output_dir}/
|
571 |
image.save(char_path)
|
572 |
character_images[character['name']] = char_path
|
573 |
|
@@ -665,7 +662,7 @@ class ProfessionalCartoonFilmGenerator:
|
|
665 |
else:
|
666 |
raise e
|
667 |
|
668 |
-
bg_path = f"{self.output_dir}/
|
669 |
image.save(bg_path)
|
670 |
background_images[scene['scene_number']] = bg_path
|
671 |
|
@@ -804,7 +801,7 @@ class ProfessionalCartoonFilmGenerator:
|
|
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}/
|
808 |
|
809 |
# Get the correct Open-Sora directory
|
810 |
current_dir = os.getcwd()
|
@@ -850,7 +847,7 @@ class ProfessionalCartoonFilmGenerator:
|
|
850 |
print(f"β No background image for scene {scene_num}")
|
851 |
return None
|
852 |
|
853 |
-
video_path = f"{self.output_dir}/
|
854 |
|
855 |
try:
|
856 |
print(f"π¬ Creating static video for scene {scene_num}...")
|
@@ -979,7 +976,7 @@ class ProfessionalCartoonFilmGenerator:
|
|
979 |
print(f"β No background image for scene {scene_num}")
|
980 |
return None
|
981 |
|
982 |
-
video_path = f"{self.output_dir}/
|
983 |
|
984 |
try:
|
985 |
print(f"π¬ Creating simple video for scene {scene_num}...")
|
@@ -1050,7 +1047,7 @@ class ProfessionalCartoonFilmGenerator:
|
|
1050 |
background_color = (100, 150, 200) # Blue-ish color
|
1051 |
|
1052 |
# Create video
|
1053 |
-
video_path = f"{self.output_dir}/
|
1054 |
fourcc = cv2.VideoWriter_fourcc(*'mp4v')
|
1055 |
fps = 24
|
1056 |
duration = 30 # 30 seconds
|
@@ -1101,13 +1098,13 @@ class ProfessionalCartoonFilmGenerator:
|
|
1101 |
print("β No videos to merge")
|
1102 |
return None
|
1103 |
|
1104 |
-
final_video_path = f"{self.output_dir}/
|
1105 |
|
1106 |
try:
|
1107 |
print("ποΈ Creating professional cartoon film...")
|
1108 |
|
1109 |
# Create concat file
|
1110 |
-
concat_file = f"{self.output_dir}/
|
1111 |
with open(concat_file, 'w') as f:
|
1112 |
for video in scene_videos:
|
1113 |
if os.path.exists(video):
|
|
|
42 |
def __init__(self):
|
43 |
self.device = "cuda" if torch.cuda.is_available() else "cpu"
|
44 |
|
45 |
+
# Use /tmp directory for Hugging Face Spaces storage
|
46 |
+
# Note: HF Spaces only allows storage in /tmp, no subdirectories allowed
|
47 |
+
self.output_dir = "/tmp"
|
48 |
+
print(f"π Using Hugging Face temp directory: {self.output_dir}")
|
|
|
49 |
|
50 |
+
# Note: Cannot create subdirectories in /tmp on HF Spaces
|
51 |
+
# Will use file prefixes instead (char_, bg_, video_, etc.)
|
|
|
|
|
52 |
|
53 |
# Model configurations for ZeroGPU optimization
|
54 |
self.models_loaded = False
|
|
|
564 |
else:
|
565 |
raise e
|
566 |
|
567 |
+
char_path = f"{self.output_dir}/char_{character['name'].replace(' ', '_')}.png"
|
568 |
image.save(char_path)
|
569 |
character_images[character['name']] = char_path
|
570 |
|
|
|
662 |
else:
|
663 |
raise e
|
664 |
|
665 |
+
bg_path = f"{self.output_dir}/bg_scene_{scene['scene_number']}.png"
|
666 |
image.save(bg_path)
|
667 |
background_images[scene['scene_number']] = bg_path
|
668 |
|
|
|
801 |
# Use the optimization function to ensure CLIP compatibility
|
802 |
prompt = self.optimize_prompt_for_clip(prompt)
|
803 |
|
804 |
+
video_path = f"{self.output_dir}/video_scene_{scene['scene_number']}.mp4"
|
805 |
|
806 |
# Get the correct Open-Sora directory
|
807 |
current_dir = os.getcwd()
|
|
|
847 |
print(f"β No background image for scene {scene_num}")
|
848 |
return None
|
849 |
|
850 |
+
video_path = f"{self.output_dir}/video_scene_{scene_num}.mp4"
|
851 |
|
852 |
try:
|
853 |
print(f"π¬ Creating static video for scene {scene_num}...")
|
|
|
976 |
print(f"β No background image for scene {scene_num}")
|
977 |
return None
|
978 |
|
979 |
+
video_path = f"{self.output_dir}/video_simple_scene_{scene_num}.mp4"
|
980 |
|
981 |
try:
|
982 |
print(f"π¬ Creating simple video for scene {scene_num}...")
|
|
|
1047 |
background_color = (100, 150, 200) # Blue-ish color
|
1048 |
|
1049 |
# Create video
|
1050 |
+
video_path = f"{self.output_dir}/video_emergency_fallback.mp4"
|
1051 |
fourcc = cv2.VideoWriter_fourcc(*'mp4v')
|
1052 |
fps = 24
|
1053 |
duration = 30 # 30 seconds
|
|
|
1098 |
print("β No videos to merge")
|
1099 |
return None
|
1100 |
|
1101 |
+
final_video_path = f"{self.output_dir}/video_professional_cartoon_film.mp4"
|
1102 |
|
1103 |
try:
|
1104 |
print("ποΈ Creating professional cartoon film...")
|
1105 |
|
1106 |
# Create concat file
|
1107 |
+
concat_file = f"{self.output_dir}/concat_list.txt"
|
1108 |
with open(concat_file, 'w') as f:
|
1109 |
for video in scene_videos:
|
1110 |
if os.path.exists(video):
|