Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,7 +4,7 @@ from PIL import Image, ImageDraw, ImageFont
|
|
| 4 |
import torch
|
| 5 |
from io import BytesIO
|
| 6 |
from diffusers import StableDiffusionImg2ImgPipeline
|
| 7 |
-
from starlette.responses import StreamingResponse
|
| 8 |
|
| 9 |
app = FastAPI()
|
| 10 |
|
|
@@ -17,10 +17,19 @@ pipe = StableDiffusionImg2ImgPipeline.from_pretrained("runwayml/stable-diffusion
|
|
| 17 |
async def root():
|
| 18 |
return {"message": "Welcome to the Text-to-Image API!"}
|
| 19 |
|
| 20 |
-
@app.get("/
|
| 21 |
-
async def
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
import torch
|
| 5 |
from io import BytesIO
|
| 6 |
from diffusers import StableDiffusionImg2ImgPipeline
|
| 7 |
+
#from starlette.responses import StreamingResponse
|
| 8 |
|
| 9 |
app = FastAPI()
|
| 10 |
|
|
|
|
| 17 |
async def root():
|
| 18 |
return {"message": "Welcome to the Text-to-Image API!"}
|
| 19 |
|
| 20 |
+
@app.get("/generate_ad")
|
| 21 |
+
async def generate_ad(prompt: str,hex_code:str, button_color:str, punchline_color:str, image_file: UploadFile):
|
| 22 |
+
|
| 23 |
+
image_bytes = await image_file.read()
|
| 24 |
+
init_image = Image.open(BytesIO(image_bytes)).convert("RGB")
|
| 25 |
+
init_image.thumbnail((768, 768))
|
| 26 |
+
# Generate the image using the text-to-image model
|
| 27 |
+
generator = torch.Generator(device=device).manual_seed(1024)
|
| 28 |
+
ad_prompt = "From init image create me a new image that will attract customers to put in a (ad template)"
|
| 29 |
+
image = pipe(prompt=ad_prompt, image=init_image, strength=0.75, guidance_scale=7.5, generator=generator).images[0]
|
| 30 |
+
|
| 31 |
+
# Create the ad template
|
| 32 |
+
ad_template = create_ad_template(image, hex_code, prompt, button_color, punchline_color)
|
| 33 |
+
|
| 34 |
+
# Return the ad template as a response
|
| 35 |
+
return ad_template
|