Spaces:
Runtime error
Runtime error
Commit
·
a617b97
1
Parent(s):
6422457
convert image to pil
Browse files
app.py
CHANGED
|
@@ -10,6 +10,7 @@ import torch
|
|
| 10 |
import subprocess
|
| 11 |
from groq import Groq
|
| 12 |
import base64
|
|
|
|
| 13 |
import os
|
| 14 |
|
| 15 |
login(token=os.environ.get("HF_API_KEY"))
|
|
@@ -41,9 +42,15 @@ pipe.set_adapters(["flat", "canny"], adapter_weights=[0.7, 0.7])
|
|
| 41 |
MAX_SEED = np.iinfo(np.int32).max
|
| 42 |
MAX_IMAGE_SIZE = 1024
|
| 43 |
|
| 44 |
-
def encode_image(image_path):
|
| 45 |
-
|
| 46 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
|
| 48 |
|
| 49 |
# @spaces.GPU #[uncomment to use ZeroGPU]
|
|
@@ -152,7 +159,7 @@ with gr.Blocks(css=css, theme=gr.themes.Soft()) as demo:
|
|
| 152 |
with gr.Column(elem_id="col-container"):
|
| 153 |
generate_button = gr.Button("Generate flat sketch", scale=0, variant="primary", elem_classes="btn btn-primary")
|
| 154 |
|
| 155 |
-
result = gr.Image(label="Result", show_label=False)
|
| 156 |
|
| 157 |
if result:
|
| 158 |
gr.Markdown("## Description of the garment:")
|
|
|
|
| 10 |
import subprocess
|
| 11 |
from groq import Groq
|
| 12 |
import base64
|
| 13 |
+
from io import BytesIO
|
| 14 |
import os
|
| 15 |
|
| 16 |
login(token=os.environ.get("HF_API_KEY"))
|
|
|
|
| 42 |
MAX_SEED = np.iinfo(np.int32).max
|
| 43 |
MAX_IMAGE_SIZE = 1024
|
| 44 |
|
| 45 |
+
# def encode_image(image_path):
|
| 46 |
+
# with open(image_path, "rb") as image_file:
|
| 47 |
+
# return base64.b64encode(image_file.read()).decode('utf-8')
|
| 48 |
+
|
| 49 |
+
def encode_image(pil_image):
|
| 50 |
+
# Convert PIL image to bytes
|
| 51 |
+
buffered = BytesIO()
|
| 52 |
+
pil_image.save(buffered, format=pil_image.format or "PNG")
|
| 53 |
+
return base64.b64encode(buffered.getvalue()).decode('utf-8')
|
| 54 |
|
| 55 |
|
| 56 |
# @spaces.GPU #[uncomment to use ZeroGPU]
|
|
|
|
| 159 |
with gr.Column(elem_id="col-container"):
|
| 160 |
generate_button = gr.Button("Generate flat sketch", scale=0, variant="primary", elem_classes="btn btn-primary")
|
| 161 |
|
| 162 |
+
result = gr.Image(label="Result", show_label=False, type="pil")
|
| 163 |
|
| 164 |
if result:
|
| 165 |
gr.Markdown("## Description of the garment:")
|