Spaces:
Sleeping
Sleeping
Update src/pipelines/embeddings.py
Browse files- src/pipelines/embeddings.py +16 -11
src/pipelines/embeddings.py
CHANGED
@@ -1,4 +1,5 @@
|
|
1 |
import random
|
|
|
2 |
import numpy as np
|
3 |
import gradio as gr
|
4 |
import matplotlib.pyplot as plt
|
@@ -16,17 +17,21 @@ age = get_axis_embeddings(young, old)
|
|
16 |
gender = get_axis_embeddings(masculine, feminine)
|
17 |
royalty = get_axis_embeddings(common, elite)
|
18 |
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
|
|
|
|
|
|
|
|
30 |
|
31 |
axis = np.vstack([gender, royalty, age])
|
32 |
axis[1] = calculate_residual(axis, axis_names)
|
|
|
1 |
import random
|
2 |
+
import spaces
|
3 |
import numpy as np
|
4 |
import gradio as gr
|
5 |
import matplotlib.pyplot as plt
|
|
|
17 |
gender = get_axis_embeddings(masculine, feminine)
|
18 |
royalty = get_axis_embeddings(common, elite)
|
19 |
|
20 |
+
@spaces.GPU(enable_queue=True)
|
21 |
+
def generate_examples(examples=examples, num_inference_steps=num_inference_steps, guidance_scale=guidance_scale):
|
22 |
+
images = []
|
23 |
+
for example in examples:
|
24 |
+
image = pipe(
|
25 |
+
prompt=example,
|
26 |
+
num_inference_steps=num_inference_steps,
|
27 |
+
guidance_scale=guidance_scale,
|
28 |
+
).images[0]
|
29 |
+
buffer = BytesIO()
|
30 |
+
image.save(buffer, format="JPEG")
|
31 |
+
encoded_image = base64.b64encode(buffer.getvalue()).decode("utf-8")
|
32 |
+
images.append("data:image/jpeg;base64, " + encoded_image)
|
33 |
+
|
34 |
+
generate_examples()
|
35 |
|
36 |
axis = np.vstack([gender, royalty, age])
|
37 |
axis[1] = calculate_residual(axis, axis_names)
|