Omnibus commited on
Commit
0afedf7
1 Parent(s): b66fb93

Update app.py

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