Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -14,17 +14,14 @@ def process_image(input_image, prompt):
|
|
| 14 |
if input_image is None:
|
| 15 |
return None, "Please upload an image"
|
| 16 |
|
| 17 |
-
# Convert PIL Image to
|
| 18 |
-
|
| 19 |
-
input_image.save(
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
# Encode to base64
|
| 23 |
-
base64_image = f"data:image/webp;base64,{base64.b64encode(img_byte_arr).decode('utf-8')}"
|
| 24 |
|
| 25 |
# Prepare headers and data
|
| 26 |
headers = {
|
| 27 |
-
"Authorization": f"Bearer {
|
| 28 |
"Content-Type": "application/json",
|
| 29 |
"Accept": "application/json"
|
| 30 |
}
|
|
@@ -45,7 +42,7 @@ def process_image(input_image, prompt):
|
|
| 45 |
response = requests.post(API_URL, headers=headers, json=data, timeout=300)
|
| 46 |
|
| 47 |
if response.status_code == 200:
|
| 48 |
-
# Convert the response base64
|
| 49 |
result = response.json()
|
| 50 |
image_bytes = base64.b64decode(result["final_image"])
|
| 51 |
output_image = Image.open(io.BytesIO(image_bytes))
|
|
@@ -108,5 +105,5 @@ with gr.Blocks(title="Room Design Diffusion", theme=gr.themes.Soft()) as demo:
|
|
| 108 |
- Be patient as generation can take a few minutes
|
| 109 |
""")
|
| 110 |
|
| 111 |
-
# Launch the app
|
| 112 |
demo.launch(share=True)
|
|
|
|
| 14 |
if input_image is None:
|
| 15 |
return None, "Please upload an image"
|
| 16 |
|
| 17 |
+
# Convert PIL Image directly to base64 string
|
| 18 |
+
buffer = io.BytesIO()
|
| 19 |
+
input_image.save(buffer, format="WEBP")
|
| 20 |
+
base64_image = f"data:image/webp;base64,{base64.b64encode(buffer.getvalue()).decode('utf-8')}"
|
|
|
|
|
|
|
|
|
|
| 21 |
|
| 22 |
# Prepare headers and data
|
| 23 |
headers = {
|
| 24 |
+
"Authorization": f"Bearer {API_TOKEN}",
|
| 25 |
"Content-Type": "application/json",
|
| 26 |
"Accept": "application/json"
|
| 27 |
}
|
|
|
|
| 42 |
response = requests.post(API_URL, headers=headers, json=data, timeout=300)
|
| 43 |
|
| 44 |
if response.status_code == 200:
|
| 45 |
+
# Convert the response base64 directly to PIL Image
|
| 46 |
result = response.json()
|
| 47 |
image_bytes = base64.b64decode(result["final_image"])
|
| 48 |
output_image = Image.open(io.BytesIO(image_bytes))
|
|
|
|
| 105 |
- Be patient as generation can take a few minutes
|
| 106 |
""")
|
| 107 |
|
| 108 |
+
# Launch the app with sharing enabled
|
| 109 |
demo.launch(share=True)
|