bluestarburst
commited on
Commit
•
376d1c9
1
Parent(s):
209feec
Upload folder using huggingface_hub
Browse files- handler.py +13 -2
handler.py
CHANGED
@@ -7,6 +7,7 @@ from huggingface_hub import hf_hub_download, try_to_load_from_cache
|
|
7 |
|
8 |
import os
|
9 |
import json
|
|
|
10 |
|
11 |
from diffusers.utils.import_utils import is_xformers_available
|
12 |
from typing import Any
|
@@ -108,9 +109,19 @@ class EndpointHandler():
|
|
108 |
|
109 |
# open the file as binary and read the data
|
110 |
with open(path, mode="rb") as file:
|
111 |
-
|
112 |
# return json response with binary data
|
113 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
114 |
|
115 |
|
116 |
# This is the entry point for the serverless function.
|
|
|
7 |
|
8 |
import os
|
9 |
import json
|
10 |
+
import base64
|
11 |
|
12 |
from diffusers.utils.import_utils import is_xformers_available
|
13 |
from typing import Any
|
|
|
109 |
|
110 |
# open the file as binary and read the data
|
111 |
with open(path, mode="rb") as file:
|
112 |
+
file_content = file.read()
|
113 |
# return json response with binary data
|
114 |
+
# Encode the binary data using Base64
|
115 |
+
base64_encoded_content = base64.b64encode(file_content).decode("utf-8")
|
116 |
+
|
117 |
+
# Create a JSON object with the Base64-encoded content
|
118 |
+
json_data = {
|
119 |
+
"filename": "output.gif",
|
120 |
+
"content": base64_encoded_content
|
121 |
+
}
|
122 |
+
|
123 |
+
# Convert the JSON object to a JSON-formatted string
|
124 |
+
return json.dumps(json_data)
|
125 |
|
126 |
|
127 |
# This is the entry point for the serverless function.
|