Imagine / app.py
Breadinlondon's picture
Update app.py
db0edb9 verified
import requests
import io
import base64
from PIL import Image
# ... (rest of your SDXL-Turbo setup) ...
def infer(prompt, negative_prompt, seed, randomize_seed, width, height, guidance_scale, num_inference_steps):
# 1. Generate the raw image
result = pipe(
prompt=prompt,
negative_prompt=negative_prompt,
guidance_scale=guidance_scale,
num_inference_steps=num_inference_steps,
width=width,
height=height,
)
raw_image = result.images[0]
# 2. Save image to a "buffer" (in memory, not on disk)
img_byte_arr = io.BytesIO()
raw_image.save(img_byte_arr, format='PNG')
img_byte_arr = img_byte_arr.getvalue()
# 3. Upload to ImgBB (Free API)
# Get a free key from https://api.imgbb.com/
IMGBB_API_KEY = "YOUR_IMGBB_API_KEY_HERE"
response = requests.post(
"https://api.imgbb.com/1/upload",
data={
"key": IMGBB_API_KEY,
"image": base64.b64encode(img_byte_arr),
}
)
# 4. Return the URL instead of the raw image
upload_data = response.json()
return upload_data["data"]["url"]