Update helper.py
Browse files
helper.py
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
import io
|
2 |
from PIL import Image
|
3 |
import base64
|
4 |
-
#Define the
|
5 |
def image_to_base64_str(pil_image):
|
6 |
byte_arr = io.BytesIO()
|
7 |
pil_image.save(byte_arr, format='PNG')
|
@@ -12,3 +12,12 @@ def base64_to_pil(img_base64):
|
|
12 |
byte_stream = io.BytesIO(base64_decoded)
|
13 |
pil_image = Image.open(byte_stream)
|
14 |
return pil_image
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import io
|
2 |
from PIL import Image
|
3 |
import base64
|
4 |
+
#Define the ConversionFunctions
|
5 |
def image_to_base64_str(pil_image):
|
6 |
byte_arr = io.BytesIO()
|
7 |
pil_image.save(byte_arr, format='PNG')
|
|
|
12 |
byte_stream = io.BytesIO(base64_decoded)
|
13 |
pil_image = Image.open(byte_stream)
|
14 |
return pil_image
|
15 |
+
|
16 |
+
#Define Image Captioner and Image Generate Functions
|
17 |
+
def captioner(image):
|
18 |
+
base64_image = image_to_base64_str(image)
|
19 |
+
result = imagecaptioningpipe(base64_image)
|
20 |
+
return result[0]['generated_text']
|
21 |
+
|
22 |
+
def generate(prompt):
|
23 |
+
return imagegenpipe(prompt).images[0]
|