Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -1,5 +1,87 @@
|
|
1 |
import subprocess
|
2 |
import os
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
|
4 |
subprocess.run(["git", "clone", "https://github.com/Nick088Official/Stable_Diffusion_Finetuned_Minecraft_Skin_Generator.git"])
|
5 |
os.chdir("Stable_Diffusion_Finetuned_Minecraft_Skin_Generator")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import subprocess
|
2 |
import os
|
3 |
+
import gradio as gr
|
4 |
+
import torch
|
5 |
+
|
6 |
+
if torch.cuda.is_available():
|
7 |
+
device = "cuda"
|
8 |
+
print("Using GPU")
|
9 |
+
else:
|
10 |
+
device = "cpu"
|
11 |
+
print("Using CPU")
|
12 |
+
|
13 |
|
14 |
subprocess.run(["git", "clone", "https://github.com/Nick088Official/Stable_Diffusion_Finetuned_Minecraft_Skin_Generator.git"])
|
15 |
os.chdir("Stable_Diffusion_Finetuned_Minecraft_Skin_Generator")
|
16 |
+
|
17 |
+
|
18 |
+
def generate(
|
19 |
+
system_prompt,
|
20 |
+
prompt,
|
21 |
+
max_new_tokens,
|
22 |
+
repetition_penalty,
|
23 |
+
temperature,
|
24 |
+
top_p,
|
25 |
+
top_k,
|
26 |
+
seed
|
27 |
+
):
|
28 |
+
|
29 |
+
input_text = f"{system_prompt}, {prompt}"
|
30 |
+
input_ids = tokenizer(input_text, return_tensors="pt").input_ids.to(device)
|
31 |
+
|
32 |
+
if seed == 0:
|
33 |
+
seed = random.randint(1, 100000)
|
34 |
+
torch.manual_seed(seed)
|
35 |
+
else:
|
36 |
+
torch.manual_seed(seed)
|
37 |
+
|
38 |
+
outputs = model.generate(
|
39 |
+
input_ids,
|
40 |
+
max_new_tokens=max_new_tokens,
|
41 |
+
repetition_penalty=repetition_penalty,
|
42 |
+
do_sample=True,
|
43 |
+
temperature=temperature,
|
44 |
+
top_p=top_p,
|
45 |
+
top_k=top_k,
|
46 |
+
)
|
47 |
+
|
48 |
+
better_prompt = tokenizer.decode(outputs[0])
|
49 |
+
better_prompt = better_prompt.replace("<pad>", "").replace("</s>", "")
|
50 |
+
return better_prompt
|
51 |
+
|
52 |
+
|
53 |
+
prompt = gr.Textbox(label="Prompt", interactive=True)
|
54 |
+
|
55 |
+
stable_diffusion_model = gr.Dropdown(["2", "xl"], interactive=True, label="Stable Diffusion Model", value="xl", type=value, info="Choose which Stable Diffusion Model to use, xl understands prompts better")
|
56 |
+
|
57 |
+
num_inference_steps = gr.Number(value=50, minimum=1, precision=0, interactive=True, label="Inference Steps", info="The number of denoising steps of the image. More denoising steps usually lead to a higher quality image at the cost of slower inference")
|
58 |
+
|
59 |
+
guidance_scale = gr.Number(value=7.5, minimum=0.1, interactive=True, label="Guidance Scale", info="How closely the generated image adheres to the prompt")
|
60 |
+
|
61 |
+
num_images_per_prompt = gr.Number(value=1, minimum=1, precision=0, interactive=True, label="Images Per Prompt", info="The number of images to make with the prompt")
|
62 |
+
|
63 |
+
model_precision_type = gr.Dropdown(["fp16", "fp32"], value="fp16" interactive=True, label="Model Precision Type", info="The precision type to load the model, like fp16 which is faster, or fp32 which gives better results")
|
64 |
+
|
65 |
+
seed = gr.Number(value=42, interactive=True, label="Seed", info="A starting point to initiate the generation process, put 0 for a random one")
|
66 |
+
|
67 |
+
examples = [
|
68 |
+
[
|
69 |
+
"A man in a purple suit wearing a tophat.",
|
70 |
+
"xl",
|
71 |
+
25,
|
72 |
+
7.5,
|
73 |
+
1,
|
74 |
+
"fp16",
|
75 |
+
42,
|
76 |
+
]
|
77 |
+
]
|
78 |
+
|
79 |
+
gr.Interface(
|
80 |
+
fn=generate,
|
81 |
+
inputs=[prompt, stable_diffusion_model, num_inference_steps, guidance_scale, num_images_per_prompt, model_precision_type, seed],
|
82 |
+
outputs=gr.Textbox(label="Generated Minecraft Skin"),
|
83 |
+
title="Stable Diffusion Finetuned Minecraft Skin Generator",
|
84 |
+
description="Make your prompts more detailed!<br>Model used: https://huggingface.co/roborovski/superprompt-v1<br>Hugging Face Space made by [Nick088](https://linktr.ee/Nick088)",
|
85 |
+
examples=examples,
|
86 |
+
concurrency_limit=20,
|
87 |
+
).launch(show_api=False)
|