Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -6,14 +6,47 @@ model_id = "SG161222/RealVisXL_V4.0"
|
|
6 |
pipe = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16)
|
7 |
pipe.to("cpu") # Use "cuda" if GPU is available
|
8 |
|
9 |
-
def generate_image(
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
|
18 |
def chatbot(prompt):
|
19 |
# Generate the image based on the user's input
|
|
|
6 |
pipe = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16)
|
7 |
pipe.to("cpu") # Use "cuda" if GPU is available
|
8 |
|
9 |
+
def generate_image(
|
10 |
+
prompt: str,
|
11 |
+
negative_prompt: str = "",
|
12 |
+
use_negative_prompt: bool = False,
|
13 |
+
style: str = DEFAULT_STYLE_NAME,
|
14 |
+
seed: int = 0,
|
15 |
+
width: int = 1024,
|
16 |
+
height: int = 1024,
|
17 |
+
guidance_scale: float = 3,
|
18 |
+
randomize_seed: bool = False,
|
19 |
+
use_resolution_binning: bool = True,
|
20 |
+
progress=gr.Progress(track_tqdm=True),
|
21 |
+
):
|
22 |
+
if check_text(prompt, negative_prompt):
|
23 |
+
raise ValueError("Prompt contains restricted words.")
|
24 |
+
|
25 |
+
prompt, negative_prompt = apply_style(style, prompt, negative_prompt)
|
26 |
+
seed = int(randomize_seed_fn(seed, randomize_seed))
|
27 |
+
generator = torch.Generator().manual_seed(seed)
|
28 |
+
|
29 |
+
if not use_negative_prompt:
|
30 |
+
negative_prompt = "" # type: ignore
|
31 |
+
negative_prompt += default_negative
|
32 |
+
|
33 |
+
options = {
|
34 |
+
"prompt": prompt,
|
35 |
+
"negative_prompt": negative_prompt,
|
36 |
+
"width": width,
|
37 |
+
"height": height,
|
38 |
+
"guidance_scale": guidance_scale,
|
39 |
+
"num_inference_steps": 25,
|
40 |
+
"generator": generator,
|
41 |
+
"num_images_per_prompt": NUM_IMAGES_PER_PROMPT,
|
42 |
+
"use_resolution_binning": use_resolution_binning,
|
43 |
+
"output_type": "pil",
|
44 |
+
}
|
45 |
+
|
46 |
+
images = pipe(**options).images + pipe2(**options).images
|
47 |
+
|
48 |
+
image_paths = [save_image(img) for img in images]
|
49 |
+
return image_paths, seed
|
50 |
|
51 |
def chatbot(prompt):
|
52 |
# Generate the image based on the user's input
|