Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,25 +1,49 @@
|
|
1 |
-
import
|
|
|
2 |
from utils import generate_sticker
|
|
|
|
|
3 |
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from fastapi import FastAPI, UploadFile, File, Form
|
2 |
+
from fastapi.responses import StreamingResponse
|
3 |
from utils import generate_sticker
|
4 |
+
from io import BytesIO
|
5 |
+
from PIL import Image
|
6 |
|
7 |
+
app = FastAPI()
|
8 |
+
|
9 |
+
@app.post("/generate")
|
10 |
+
async def generate(image: UploadFile = File(...), prompt: str = Form(...)):
|
11 |
+
# Read image file as PIL
|
12 |
+
image_pil = Image.open(BytesIO(await image.read()))
|
13 |
+
# Generate sticker
|
14 |
+
result_img = generate_sticker(image_pil, prompt)
|
15 |
+
# Save output image to a buffer
|
16 |
+
buf = BytesIO()
|
17 |
+
result_img.save(buf, format="PNG")
|
18 |
+
buf.seek(0)
|
19 |
+
return StreamingResponse(buf, media_type="image/png")
|
20 |
+
|
21 |
+
# If you want to run directly: uvicorn app:app --host 0.0.0.0 --port 8000
|
22 |
+
|
23 |
+
|
24 |
+
|
25 |
+
# import gradio as gr
|
26 |
+
# from utils import generate_sticker
|
27 |
+
|
28 |
+
# def predict(image, prompt):
|
29 |
+
# result_img = generate_sticker(image, prompt)
|
30 |
+
# return result_img # Should be PIL Image or np.array or filepath
|
31 |
+
|
32 |
+
# with gr.Blocks() as demo:
|
33 |
+
# gr.Markdown("# 🦄 AI Sticker Generator (Stable Diffusion + IP-Adapter)")
|
34 |
+
# with gr.Row():
|
35 |
+
# image_input = gr.Image(type="pil", label="Upload your photo")
|
36 |
+
# prompt_input = gr.Textbox(
|
37 |
+
# label="Prompt (style or mood for emoji)",
|
38 |
+
# value="cartoon emoji, white outline, clean background",
|
39 |
+
# )
|
40 |
+
# output_image = gr.Image(label="Sticker Output")
|
41 |
+
# run_btn = gr.Button("Generate Sticker")
|
42 |
+
# run_btn.click(
|
43 |
+
# predict,
|
44 |
+
# inputs=[image_input, prompt_input],
|
45 |
+
# outputs=output_image
|
46 |
+
# )
|
47 |
+
|
48 |
+
# if __name__ == "__main__":
|
49 |
+
# demo.launch(server_name="0.0.0.0", share=True)
|