Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -27,6 +27,9 @@ stable_diffusion = StableDiffusionPipeline.from_pretrained(
|
|
27 |
torch_dtype=torch.float16 if torch.cuda.is_available() else torch.float32
|
28 |
).to(device)
|
29 |
|
|
|
|
|
|
|
30 |
nltk.download("punkt")
|
31 |
|
32 |
summarizer = pipeline(
|
@@ -61,11 +64,30 @@ def summarize_story(story):
|
|
61 |
|
62 |
def generate_images(story):
|
63 |
scenes = summarize_story(story)
|
64 |
-
prompts = [f"Highly detailed, cinematic scene: {scene}, digital art, 4K, realistic lighting" for scene in scenes]
|
65 |
images = []
|
66 |
-
|
67 |
-
|
68 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
69 |
return images
|
70 |
|
71 |
def text_to_speech(story):
|
|
|
27 |
torch_dtype=torch.float16 if torch.cuda.is_available() else torch.float32
|
28 |
).to(device)
|
29 |
|
30 |
+
|
31 |
+
stable_diffusion.vae.enable_tiling = False
|
32 |
+
|
33 |
nltk.download("punkt")
|
34 |
|
35 |
summarizer = pipeline(
|
|
|
64 |
|
65 |
def generate_images(story):
|
66 |
scenes = summarize_story(story)
|
|
|
67 |
images = []
|
68 |
+
|
69 |
+
# Περιορισμός σε μέγιστο 3 σκηνές για αποφυγή υπερφόρτωσης
|
70 |
+
scenes = scenes[:min(len(scenes), 3)]
|
71 |
+
|
72 |
+
for prompt in scenes:
|
73 |
+
try:
|
74 |
+
with torch.no_grad(): # Μειώνει τη χρήση μνήμης
|
75 |
+
prompt_text = f"Highly detailed, cinematic scene: {prompt}, digital art, 4K, realistic lighting"
|
76 |
+
# Προσθέτω παραμέτρους για καλύτερη διαχείριση μνήμης
|
77 |
+
image = stable_diffusion(
|
78 |
+
prompt_text,
|
79 |
+
num_inference_steps=30, # Μείωση από το προεπιλεγμένο 50
|
80 |
+
guidance_scale=7.5
|
81 |
+
).images[0]
|
82 |
+
images.append(image)
|
83 |
+
# Καθαρισμός μνήμης μετά από κάθε δημιουργία
|
84 |
+
if torch.cuda.is_available():
|
85 |
+
torch.cuda.empty_cache()
|
86 |
+
except Exception as e:
|
87 |
+
print(f"Error generating image for scene: {e}")
|
88 |
+
# Συνέχισε με την επόμενη σκηνή σε περίπτωση σφάλματος
|
89 |
+
continue
|
90 |
+
|
91 |
return images
|
92 |
|
93 |
def text_to_speech(story):
|