Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -15,72 +15,75 @@ ckpt = "sdxl_lightning_4step_unet.safetensors" # Use the correct ckpt for your s
|
|
15 |
pipe_box=[]
|
16 |
|
17 |
@spaces.GPU()
|
18 |
-
def
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
{
|
54 |
-
{
|
55 |
-
{
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
|
|
|
|
|
|
|
15 |
pipe_box=[]
|
16 |
|
17 |
@spaces.GPU()
|
18 |
+
def main():
|
19 |
+
def init():
|
20 |
+
device="cuda:0"
|
21 |
+
#unet = UNet2DConditionModel.from_config(base, subfolder="unet").to(device, torch.float16)
|
22 |
+
#unet.load_state_dict(load_file(hf_hub_download(repo, ckpt), device=device))
|
23 |
+
#pipe = StableDiffusionXLPipeline.from_pretrained(base, unet=unet, torch_dtype=torch.float16, variant="fp16").to(device)
|
24 |
+
pipe = StableDiffusionXLPipeline.from_pretrained(base, torch_dtype=torch.float16, variant="fp16").to(device)
|
25 |
+
# Ensure sampler uses "trailing" timesteps.
|
26 |
+
pipe.scheduler = EulerDiscreteScheduler.from_config(pipe.scheduler.config, timestep_spacing="trailing")
|
27 |
+
pipe_box.append(pipe)
|
28 |
+
#init()
|
29 |
+
@spaces.GPU()
|
30 |
+
def run():
|
31 |
+
init()
|
32 |
+
pipe=pipe_box[0]
|
33 |
+
# Ensure using the same inference steps as the loaded model and CFG set to 0.
|
34 |
+
return pipe("A cat", num_inference_steps=4, guidance_scale=0).images[0].save("output.png")
|
35 |
+
|
36 |
+
|
37 |
+
|
38 |
+
|
39 |
+
'''
|
40 |
+
tokenizer = AutoTokenizer.from_pretrained("EleutherAI/gpt-neox-20b")
|
41 |
+
|
42 |
+
model = transformers.AutoModelForCausalLM.from_pretrained(
|
43 |
+
'mosaicml/mpt-7b-instruct',
|
44 |
+
trust_remote_code=True
|
45 |
+
)
|
46 |
+
|
47 |
+
|
48 |
+
pipe = pipeline('text-generation', model=model, tokenizer=tokenizer, device='cuda:0')
|
49 |
+
|
50 |
+
INSTRUCTION_KEY = "### Instruction:"
|
51 |
+
RESPONSE_KEY = "### Response:"
|
52 |
+
INTRO_BLURB = "Below is an instruction that describes a task. Write a response that appropriately completes the request."
|
53 |
+
PROMPT_FOR_GENERATION_FORMAT = """{intro}
|
54 |
+
{instruction_key}
|
55 |
+
{instruction}
|
56 |
+
{response_key}
|
57 |
+
""".format(
|
58 |
+
intro=INTRO_BLURB,
|
59 |
+
instruction_key=INSTRUCTION_KEY,
|
60 |
+
instruction="{instruction}",
|
61 |
+
response_key=RESPONSE_KEY,
|
62 |
+
)
|
63 |
+
|
64 |
+
example = "James decides to run 3 sprints 3 times a week. He runs 60 meters each sprint. How many total meters does he run a week? Explain before answering."
|
65 |
+
fmt_ex = PROMPT_FOR_GENERATION_FORMAT.format(instruction=example)
|
66 |
+
|
67 |
+
|
68 |
+
|
69 |
+
|
70 |
+
@spaces.GPU
|
71 |
+
def run():
|
72 |
+
with torch.autocast('cuda', dtype=torch.bfloat16):
|
73 |
+
return(
|
74 |
+
pipe('Here is a recipe for vegan banana bread:\n',
|
75 |
+
max_new_tokens=100,
|
76 |
+
do_sample=True,
|
77 |
+
use_cache=True))
|
78 |
+
'''
|
79 |
+
|
80 |
+
|
81 |
+
with gr.Blocks() as app:
|
82 |
+
btn = gr.Button()
|
83 |
+
#outp=gr.Textbox()
|
84 |
+
outp=gr.Image()
|
85 |
+
btn.click(run,None,outp)
|
86 |
+
app.launch()
|
87 |
+
|
88 |
+
if __name__ == "__main__":
|
89 |
+
main()
|