Update app.py
Browse files
app.py
CHANGED
@@ -1,28 +1,13 @@
|
|
1 |
-
|
2 |
-
|
3 |
from diffusers import StableDiffusionPipeline
|
4 |
-
import torch, io
|
5 |
-
from PIL import Image
|
6 |
|
7 |
-
|
8 |
-
pipe = StableDiffusionPipeline.from_pretrained(
|
9 |
-
|
10 |
-
torch_dtype=torch.float16,
|
11 |
-
safety_checker=None # Optional: disable safety checker
|
12 |
-
).to("cuda")
|
13 |
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
return {"status": "ok", "message": "FastAPI server is running!"}
|
18 |
|
19 |
-
|
20 |
-
async def generate(
|
21 |
-
file: UploadFile = File(...), prompt: str = Form(...)
|
22 |
-
):
|
23 |
-
image = Image.open(io.BytesIO(await file.read())).convert("RGB")
|
24 |
-
result = pipe(prompt=prompt, image=image, guidance_scale=7.5).images[0]
|
25 |
-
buf = io.BytesIO()
|
26 |
-
result.save(buf, format="PNG")
|
27 |
-
buf.seek(0)
|
28 |
-
return StreamingResponse(buf, media_type="image/png")
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import torch
|
3 |
from diffusers import StableDiffusionPipeline
|
|
|
|
|
4 |
|
5 |
+
model_id = "runwayml/stable-diffusion-v1-5"
|
6 |
+
pipe = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16)
|
7 |
+
pipe = pipe.to("cuda")
|
|
|
|
|
|
|
8 |
|
9 |
+
def generate(prompt):
|
10 |
+
image = pipe(prompt).images[0]
|
11 |
+
return image
|
|
|
12 |
|
13 |
+
gr.Interface(fn=generate, inputs="text", outputs="image").launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|