Spaces:
Runtime error
Runtime error
Axel-Student
commited on
Commit
·
50bfe7a
1
Parent(s):
4c1f5fb
init ai model with generating imgs
Browse files- Dockerfile +11 -0
- app.py +29 -0
Dockerfile
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FROM python:3.10
|
| 2 |
+
|
| 3 |
+
WORKDIR /app
|
| 4 |
+
|
| 5 |
+
RUN pip install --no-cache-dir torch torchvision torchaudio diffusers gradio
|
| 6 |
+
RUN pip install --no-cache-dir black-forest-labs-flux
|
| 7 |
+
COPY . /app
|
| 8 |
+
|
| 9 |
+
EXPOSE 7860
|
| 10 |
+
|
| 11 |
+
CMD ["python", "app.py"]
|
app.py
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import torch
|
| 2 |
+
from diffusers import FluxPipeline
|
| 3 |
+
import gradio as gr # type: ignore
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
pipe = FluxPipeline.from_pretrained("black-forest-labs/FLUX.1-dev", torch_dtype=torch.bfloat16)
|
| 7 |
+
pipe.enable_model_cpu_offload() #save some VRAM by offloading the model to CPU. Remove this if you have enough GPU power
|
| 8 |
+
|
| 9 |
+
prompt = "A cat holding a sign that says hello world"
|
| 10 |
+
image = pipe(
|
| 11 |
+
prompt,
|
| 12 |
+
height=1024,
|
| 13 |
+
width=1024,
|
| 14 |
+
guidance_scale=3.5,
|
| 15 |
+
num_inference_steps=50,
|
| 16 |
+
max_sequence_length=512,
|
| 17 |
+
generator=torch.Generator("cpu").manual_seed(0)
|
| 18 |
+
).images[0]
|
| 19 |
+
image.save("flux-dev.png")
|
| 20 |
+
|
| 21 |
+
gradio_app = gr.Interface(
|
| 22 |
+
image,
|
| 23 |
+
inputs=gr.Image(label="Select hot dog candidate", sources=['upload', 'webcam'], type="pil"),
|
| 24 |
+
outputs=[gr.Image(label="Processed Image"), gr.Label(label="Result", num_top_classes=2)],
|
| 25 |
+
title="Hot Dog? Or Not?",
|
| 26 |
+
)
|
| 27 |
+
|
| 28 |
+
if __name__ == "__main__":
|
| 29 |
+
gradio_app.launch()
|