Spaces:
Sleeping
Sleeping
Update utils.py
Browse files
utils.py
CHANGED
@@ -1,24 +1,20 @@
|
|
1 |
-
|
2 |
from diffusers import StableDiffusionPipeline
|
3 |
import torch
|
|
|
|
|
4 |
|
5 |
-
#
|
6 |
model_id = "stabilityai/stable-diffusion-2"
|
7 |
-
pipe = StableDiffusionPipeline.from_pretrained(
|
8 |
-
|
|
|
|
|
|
|
9 |
|
10 |
-
#def generate_image_from_prompt(prompt):
|
11 |
-
# image = pipe(prompt).images[0]
|
12 |
-
# return image
|
13 |
def generate_image_from_prompt(prompt):
|
14 |
-
|
15 |
-
image = pipe(styled_prompt).images[0]
|
16 |
return image
|
17 |
|
18 |
-
# Optional: GROQ function (if needed)
|
19 |
-
import os
|
20 |
-
import requests
|
21 |
-
|
22 |
GROQ_API_KEY = os.getenv("GROQ_API_KEY")
|
23 |
|
24 |
def split_into_scenes(story_text, num_scenes=5):
|
@@ -35,6 +31,7 @@ Respond in a numbered list format.
|
|
35 |
"Authorization": f"Bearer {GROQ_API_KEY}",
|
36 |
"Content-Type": "application/json"
|
37 |
}
|
|
|
38 |
json_data = {
|
39 |
"messages": [
|
40 |
{"role": "system", "content": "You are a screenplay breakdown assistant."},
|
@@ -50,6 +47,7 @@ Respond in a numbered list format.
|
|
50 |
return []
|
51 |
|
52 |
output = response.json()["choices"][0]["message"]["content"]
|
|
|
53 |
scenes = []
|
54 |
for line in output.strip().split('\n'):
|
55 |
line = line.strip()
|
|
|
|
|
1 |
from diffusers import StableDiffusionPipeline
|
2 |
import torch
|
3 |
+
import os
|
4 |
+
import requests
|
5 |
|
6 |
+
# Initialize model only once at the top
|
7 |
model_id = "stabilityai/stable-diffusion-2"
|
8 |
+
pipe = StableDiffusionPipeline.from_pretrained(
|
9 |
+
model_id,
|
10 |
+
torch_dtype=torch.float16 if torch.cuda.is_available() else torch.float32
|
11 |
+
)
|
12 |
+
pipe = pipe.to("cuda" if torch.cuda.is_available() else "cpu")
|
13 |
|
|
|
|
|
|
|
14 |
def generate_image_from_prompt(prompt):
|
15 |
+
image = pipe(prompt).images[0]
|
|
|
16 |
return image
|
17 |
|
|
|
|
|
|
|
|
|
18 |
GROQ_API_KEY = os.getenv("GROQ_API_KEY")
|
19 |
|
20 |
def split_into_scenes(story_text, num_scenes=5):
|
|
|
31 |
"Authorization": f"Bearer {GROQ_API_KEY}",
|
32 |
"Content-Type": "application/json"
|
33 |
}
|
34 |
+
|
35 |
json_data = {
|
36 |
"messages": [
|
37 |
{"role": "system", "content": "You are a screenplay breakdown assistant."},
|
|
|
47 |
return []
|
48 |
|
49 |
output = response.json()["choices"][0]["message"]["content"]
|
50 |
+
|
51 |
scenes = []
|
52 |
for line in output.strip().split('\n'):
|
53 |
line = line.strip()
|