Samuel L Meyers
commited on
Commit
·
58a83d5
1
Parent(s):
40435b5
Initial test
Browse files- Dockerfile +14 -0
- code/app.py +33 -0
- code/requirements.txt +6 -0
Dockerfile
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# read the doc: https://huggingface.co/docs/hub/spaces-sdks-docker
|
| 2 |
+
# you will also find guides on how best to write your Dockerfile
|
| 3 |
+
|
| 4 |
+
FROM python:3.9
|
| 5 |
+
|
| 6 |
+
WORKDIR /code
|
| 7 |
+
|
| 8 |
+
COPY ./requirements.txt /code/requirements.txt
|
| 9 |
+
|
| 10 |
+
RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
|
| 11 |
+
|
| 12 |
+
COPY . .
|
| 13 |
+
|
| 14 |
+
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "7860"]
|
code/app.py
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from diffusers import AutoPipelineForText2Image
|
| 2 |
+
import torch
|
| 3 |
+
import gradio as gr
|
| 4 |
+
|
| 5 |
+
pipeline_text2image = AutoPipelineForText2Image.from_pretrained(
|
| 6 |
+
"stabilityai/stable-diffusion-xl-base-1.0", use_safetensors=True
|
| 7 |
+
)
|
| 8 |
+
|
| 9 |
+
def gradio_txt2img(prompt):
|
| 10 |
+
return pipeline_text2image(prompt=prompt).images[0]
|
| 11 |
+
|
| 12 |
+
def api_txt2base64(prompt):
|
| 13 |
+
return gradio_txt2img(prompt).to_base64()
|
| 14 |
+
|
| 15 |
+
with gr.Blocks() as demo:
|
| 16 |
+
gr.Markdown("## Stable Diffusion XL - Modded to Hell Edition")
|
| 17 |
+
gr.Markdown("## Text to Image\n\nConverts a prompt into an image.")
|
| 18 |
+
with gr.Row():
|
| 19 |
+
with gr.Column():
|
| 20 |
+
txt2img_prompt = gr.Textbox(label="Input", lines=2, max_lines=2)
|
| 21 |
+
txt2img_btn = gr.Button("Generate")
|
| 22 |
+
with gr.Column():
|
| 23 |
+
txt2img_out = gr.Image()
|
| 24 |
+
with gr.Row():
|
| 25 |
+
with gr.Column():
|
| 26 |
+
txt2b64_prompt = gr.Textbox(label="Input", lines=2, max_lines=2)
|
| 27 |
+
txt2b64_btn = gr.Button("Generate")
|
| 28 |
+
with gr.Column():
|
| 29 |
+
txt2b64_out = gr.Image()
|
| 30 |
+
txt2img_btn.click(fn=gradio_txt2img, inputs=txt2img_prompt, outputs=txt2img_out, queue=True, api_name="gradio_txt2img")
|
| 31 |
+
txt2b64_btn.click(fn=gradio_txt2img, inputs=txt2b64_prompt, outputs=txt2b64_out, queue=True, api_name="gradio_txt2b64")
|
| 32 |
+
|
| 33 |
+
demo.launch()
|
code/requirements.txt
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio
|
| 2 |
+
transformers
|
| 3 |
+
diffusers
|
| 4 |
+
accelerate
|
| 5 |
+
safetensors
|
| 6 |
+
omegaconf
|