Spaces:
Sleeping
Sleeping
Update app.py
Browse files12345678910111213141516171819202122232425import gradio as grfrom utils import generate_stickerdef predict(image, prompt):result_img = generate_sticker(image, prompt)return result_img # Should be PIL Image or np.array or filepathwith gr.Blocks() as demo:gr.Markdown("# 🦄 AI Sticker Generator (Stable Diffusion + IP-Adapter)")with gr.Row():image_input = gr.Image(type="pil", label="Upload your photo")prompt_input = gr.Textbox(label="Prompt (style or mood for emoji)",value="cartoon emoji, white outline, clean background",)output_image = gr.Image(label="Sticker Output")run_btn = gr.Button("Generate Sticker")run_btn.click(predict,inputs=[image_input, prompt_input],outputs=output_image)if __name__ == "__main__":demo.launch(server_name="0.0.0.0", share=True)12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849from fastapi import FastAPI, UploadFile, File, Formfrom fastapi.responses import StreamingResponsefrom utils import generate_stickerfrom io import BytesIOfrom PIL import Imageapp = FastAPI()@app.post("/generate")async def generate(image: UploadFile = File(...), prompt: str = Form(...)):# Read image file as PILimage_pil = Image.open(BytesIO(await image.read()))# Generate stickerresult_img = generate_sticker(image_pil, prompt)# Save output image to a bufferbuf = BytesIO()result_img.save(buf, format="PNG")buf.seek(0)return StreamingResponse(buf, media_type="image/png")# If you want to run directly: uvicorn app:app --host 0.0.0.0 --port 8000# import gradio as gr# from utils import generate_sticker# def predict(image, prompt):# result_img = generate_sticker(image, prompt)# return result_img # Should be PIL Image or np.array or filepath# with gr.Blocks() as demo:# gr.Markdown("# 🦄 AI Sticker Generator (Stable Diffusion + IP-Adapter)")# with gr.Row():# image_input = gr.Image(type="pil", label="Upload your photo")# prompt_input = gr.Textbox(# label="Prompt (style or mood for emoji)",# value="cartoon emoji, white outline, clean background",# )# output_image = gr.Image(label="Sticker Output")# run_btn = gr.Button("Generate Sticker")# run_btn.click(# predict,# inputs=[image_input, prompt_input],# outputs=output_image# )# if __name__ == "__main__":# demo.launch(server_name="0.0.0.0", share=True)
app.py+47-23