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