add custom handler
Browse files- __pycache__/handler.cpython-38.pyc +0 -0
- handler.py +11 -4
__pycache__/handler.cpython-38.pyc
CHANGED
Binary files a/__pycache__/handler.cpython-38.pyc and b/__pycache__/handler.cpython-38.pyc differ
|
|
handler.py
CHANGED
@@ -1,4 +1,5 @@
|
|
1 |
from typing import Dict, List, Any
|
|
|
2 |
|
3 |
import tensorflow as tf
|
4 |
from keras_cv.models.generative.stable_diffusion.text_encoder import TextEncoder
|
@@ -47,7 +48,7 @@ class EndpointHandler():
|
|
47 |
context = encoded_text
|
48 |
|
49 |
unconditional_context = tf.repeat(
|
50 |
-
_get_unconditional_context(), batch_size, axis=0
|
51 |
)
|
52 |
|
53 |
return context, unconditional_context
|
@@ -57,7 +58,13 @@ class EndpointHandler():
|
|
57 |
prompt = data.pop("inputs", data)
|
58 |
batch_size = data.pop("batch_size", 1)
|
59 |
|
60 |
-
encoded_text = encode_text(prompt)
|
61 |
-
context, unconditional_context = get_contexts(encoded_text, batch_size)
|
62 |
|
63 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
from typing import Dict, List, Any
|
2 |
+
import base64
|
3 |
|
4 |
import tensorflow as tf
|
5 |
from keras_cv.models.generative.stable_diffusion.text_encoder import TextEncoder
|
|
|
48 |
context = encoded_text
|
49 |
|
50 |
unconditional_context = tf.repeat(
|
51 |
+
self._get_unconditional_context(), batch_size, axis=0
|
52 |
)
|
53 |
|
54 |
return context, unconditional_context
|
|
|
58 |
prompt = data.pop("inputs", data)
|
59 |
batch_size = data.pop("batch_size", 1)
|
60 |
|
61 |
+
encoded_text = self.encode_text(prompt)
|
62 |
+
context, unconditional_context = self.get_contexts(encoded_text, batch_size)
|
63 |
|
64 |
+
context_b64 = base64.b64encode(context.numpy().tobytes())
|
65 |
+
context_b64str = context_b64.decode()
|
66 |
+
|
67 |
+
unconditional_context_b64 = base64.b64encode(unconditional_context.numpy().tobytes())
|
68 |
+
unconditional_context_b64str = unconditional_context_b64.decode()
|
69 |
+
|
70 |
+
return context_b64str, unconditional_context_b64str
|