Spaces:
Sleeping
Sleeping
updates
Browse files- .DS_Store +0 -0
- Dockerfile +1 -1
- app.py +0 -15
- main.py +1 -1
- text_to_image.py +0 -50
.DS_Store
ADDED
Binary file (6.15 kB). View file
|
|
Dockerfile
CHANGED
@@ -37,7 +37,7 @@ COPY --chown=user . $HOME/app
|
|
37 |
RUN pip install gdown
|
38 |
RUN --mount=type=secret,id=truepic_sign_gdoc_id,mode=0444,required=true \
|
39 |
gdown --id $(cat /run/secrets/truepic_sign_gdoc_id)
|
40 |
-
RUN tar -xf truepic-sign-v0.2.0-ubuntu-20.04.tar.gz
|
41 |
RUN chmod +x truepic-sign
|
42 |
|
43 |
WORKDIR $HOME/app
|
|
|
37 |
RUN pip install gdown
|
38 |
RUN --mount=type=secret,id=truepic_sign_gdoc_id,mode=0444,required=true \
|
39 |
gdown --id $(cat /run/secrets/truepic_sign_gdoc_id)
|
40 |
+
RUN tar -xf truepic-sign-v0.2.0-ubuntu-20.04.tar.gz
|
41 |
RUN chmod +x truepic-sign
|
42 |
|
43 |
WORKDIR $HOME/app
|
app.py
DELETED
@@ -1,15 +0,0 @@
|
|
1 |
-
from text_to_image import TextToImageTool
|
2 |
-
import gradio as gr
|
3 |
-
|
4 |
-
tool = TextToImageTool()
|
5 |
-
|
6 |
-
def fn(*args, **kwargs):
|
7 |
-
return tool(*args, **kwargs)
|
8 |
-
|
9 |
-
gr.Interface(
|
10 |
-
fn=fn,
|
11 |
-
inputs=tool.inputs,
|
12 |
-
outputs=tool.outputs,
|
13 |
-
title="TextToImageTool",
|
14 |
-
article=tool.description,
|
15 |
-
).queue(concurrency_count=5).launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
main.py
CHANGED
@@ -13,7 +13,7 @@ import uuid
|
|
13 |
import torch
|
14 |
from diffusers import StableDiffusionPipeline, DPMSolverMultistepScheduler, EulerDiscreteScheduler
|
15 |
|
16 |
-
app = FastAPI()
|
17 |
|
18 |
@app.get("/generate")
|
19 |
def generate_image(prompt, inference_steps, model):
|
|
|
13 |
import torch
|
14 |
from diffusers import StableDiffusionPipeline, DPMSolverMultistepScheduler, EulerDiscreteScheduler
|
15 |
|
16 |
+
app = FastAPI()
|
17 |
|
18 |
@app.get("/generate")
|
19 |
def generate_image(prompt, inference_steps, model):
|
text_to_image.py
DELETED
@@ -1,50 +0,0 @@
|
|
1 |
-
from transformers.tools.base import Tool, get_default_device
|
2 |
-
from transformers.utils import is_accelerate_available
|
3 |
-
import torch
|
4 |
-
|
5 |
-
from diffusers import DiffusionPipeline, DPMSolverMultistepScheduler
|
6 |
-
|
7 |
-
|
8 |
-
TEXT_TO_IMAGE_DESCRIPTION = (
|
9 |
-
"This is a tool that creates an image according to a prompt, which is a text description. It takes an input named `prompt` which "
|
10 |
-
"contains the image description and outputs an image."
|
11 |
-
)
|
12 |
-
|
13 |
-
|
14 |
-
class TextToImageTool(Tool):
|
15 |
-
default_checkpoint = "runwayml/stable-diffusion-v1-5"
|
16 |
-
description = TEXT_TO_IMAGE_DESCRIPTION
|
17 |
-
inputs = ['text']
|
18 |
-
outputs = ['image']
|
19 |
-
|
20 |
-
def __init__(self, device=None, **hub_kwargs) -> None:
|
21 |
-
if not is_accelerate_available():
|
22 |
-
raise ImportError("Accelerate should be installed in order to use tools.")
|
23 |
-
|
24 |
-
super().__init__()
|
25 |
-
|
26 |
-
self.device = device
|
27 |
-
self.pipeline = None
|
28 |
-
self.hub_kwargs = hub_kwargs
|
29 |
-
|
30 |
-
def setup(self):
|
31 |
-
if self.device is None:
|
32 |
-
self.device = get_default_device()
|
33 |
-
|
34 |
-
self.pipeline = DiffusionPipeline.from_pretrained(self.default_checkpoint)
|
35 |
-
self.pipeline.scheduler = DPMSolverMultistepScheduler.from_config(self.pipeline.scheduler.config)
|
36 |
-
self.pipeline.to(self.device)
|
37 |
-
|
38 |
-
if self.device.type == "cuda":
|
39 |
-
self.pipeline.to(torch_dtype=torch.float16)
|
40 |
-
|
41 |
-
self.is_initialized = True
|
42 |
-
|
43 |
-
def __call__(self, prompt):
|
44 |
-
if not self.is_initialized:
|
45 |
-
self.setup()
|
46 |
-
|
47 |
-
negative_prompt = "low quality, bad quality, deformed, low resolution"
|
48 |
-
added_prompt = " , highest quality, highly realistic, very high resolution"
|
49 |
-
|
50 |
-
return self.pipeline(prompt + added_prompt, negative_prompt=negative_prompt, num_inference_steps=25).images[0]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|