Create api_app.py
Browse files- api_app.py +16 -0
api_app.py
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from diffusers import StableDiffusionPipeline
|
| 3 |
+
import torch
|
| 4 |
+
|
| 5 |
+
model_id = "runwayml/stable-diffusion-v1-5"
|
| 6 |
+
|
| 7 |
+
pipe = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float32)
|
| 8 |
+
pipe = pipe.to("cpu")
|
| 9 |
+
|
| 10 |
+
def generate_image(prompt):
|
| 11 |
+
image = pipe(prompt).images[0]
|
| 12 |
+
return image
|
| 13 |
+
|
| 14 |
+
demo = gr.Interface(fn=generate_image, inputs="text", outputs="image", title="Free AI Image Generator API")
|
| 15 |
+
|
| 16 |
+
demo.launch(share=True)
|