Spaces:
Runtime error
Runtime error
Shaffique Aljoofri
commited on
Commit
·
179662f
1
Parent(s):
7804a41
Update app.py
Browse files
app.py
CHANGED
|
@@ -6,11 +6,10 @@ hf_api_itt_base = os.environ['HF_API_ITT_BASE']
|
|
| 6 |
|
| 7 |
##### Helper functions #####
|
| 8 |
import io, base64, requests, json
|
| 9 |
-
from PIL import Image
|
| 10 |
|
| 11 |
-
def image_to_base64_str(
|
| 12 |
byte_arr = io.BytesIO()
|
| 13 |
-
|
| 14 |
byte_arr = byte_arr.getvalue()
|
| 15 |
return str(base64.b64encode(byte_arr).decode('utf-8'))
|
| 16 |
|
|
@@ -28,8 +27,7 @@ def get_completion(inputs, parameters = None, ENDPOINT_URL = hf_api_itt_base):
|
|
| 28 |
return json.loads(response.content.decode("utf-8"))
|
| 29 |
|
| 30 |
def captioner(image):
|
| 31 |
-
|
| 32 |
-
base64_image = image_to_base64_str(pil_image)
|
| 33 |
result = get_completion(base64_image)
|
| 34 |
return result[0]['generated_text']
|
| 35 |
|
|
|
|
| 6 |
|
| 7 |
##### Helper functions #####
|
| 8 |
import io, base64, requests, json
|
|
|
|
| 9 |
|
| 10 |
+
def image_to_base64_str(image):
|
| 11 |
byte_arr = io.BytesIO()
|
| 12 |
+
image.save(byte_arr, format='PNG')
|
| 13 |
byte_arr = byte_arr.getvalue()
|
| 14 |
return str(base64.b64encode(byte_arr).decode('utf-8'))
|
| 15 |
|
|
|
|
| 27 |
return json.loads(response.content.decode("utf-8"))
|
| 28 |
|
| 29 |
def captioner(image):
|
| 30 |
+
base64_image = image_to_base64_str(image)
|
|
|
|
| 31 |
result = get_completion(base64_image)
|
| 32 |
return result[0]['generated_text']
|
| 33 |
|