Spaces:
Runtime error
Runtime error
isaul19
commited on
Commit
Β·
fef623c
1
Parent(s):
810e8fb
base
Browse files- app.py +29 -0
- requirements.txt +16 -0
app.py
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from PIL import Image
|
| 3 |
+
from io import BytesIO
|
| 4 |
+
import torch
|
| 5 |
+
from torch.cuda.amp import autocast
|
| 6 |
+
from diffusers import DiffusionPipeline
|
| 7 |
+
import os
|
| 8 |
+
|
| 9 |
+
model_id = "stabilityai/stable-diffusion-xl-base-1.0"
|
| 10 |
+
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 11 |
+
|
| 12 |
+
pipe = DiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float32, use_safetensors=True, variant="fp16")
|
| 13 |
+
pipe = pipe.to(device)
|
| 14 |
+
|
| 15 |
+
def generate_image(prompt: str, secret: str):
|
| 16 |
+
if secret != os.getenv("SECRET_KEY"):
|
| 17 |
+
return "Not Authorized"
|
| 18 |
+
|
| 19 |
+
with autocast(device):
|
| 20 |
+
image = pipe(prompt, guidance_scale=8.5).images[0]
|
| 21 |
+
|
| 22 |
+
buffer = BytesIO()
|
| 23 |
+
image.save(buffer, format="PNG")
|
| 24 |
+
buffer.seek(0)
|
| 25 |
+
|
| 26 |
+
return buffer
|
| 27 |
+
|
| 28 |
+
iface = gr.Interface(fn=generate_image, inputs=[gr.inputs.Textbox(label="prompt"), gr.inputs.Textbox(label="secret")], outputs="bytes")
|
| 29 |
+
iface.launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# fastapi
|
| 2 |
+
# uvicorn
|
| 3 |
+
# torch
|
| 4 |
+
# transformers
|
| 5 |
+
# diffusers
|
| 6 |
+
|
| 7 |
+
gradio
|
| 8 |
+
torch
|
| 9 |
+
diffusers
|
| 10 |
+
transformers
|
| 11 |
+
accelerate
|
| 12 |
+
uvicorn
|
| 13 |
+
datasets
|
| 14 |
+
torch
|
| 15 |
+
soundfile
|
| 16 |
+
sentencepiece
|