Omnibus commited on
Commit
81b31fb
1 Parent(s): 1a0b023

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -5
app.py CHANGED
@@ -1,9 +1,33 @@
1
  import spaces
2
  import gradio as gr
3
- import transformers
4
- from transformers import AutoTokenizer
5
- from transformers import pipeline
 
 
 
6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7
  tokenizer = AutoTokenizer.from_pretrained("EleutherAI/gpt-neox-20b")
8
 
9
  model = transformers.AutoModelForCausalLM.from_pretrained(
@@ -31,6 +55,9 @@ PROMPT_FOR_GENERATION_FORMAT = """{intro}
31
  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."
32
  fmt_ex = PROMPT_FOR_GENERATION_FORMAT.format(instruction=example)
33
 
 
 
 
34
  @spaces.GPU
35
  def run():
36
  with torch.autocast('cuda', dtype=torch.bfloat16):
@@ -39,12 +66,13 @@ def run():
39
  max_new_tokens=100,
40
  do_sample=True,
41
  use_cache=True))
42
-
43
 
44
 
45
  with gr.Blocks() as app:
46
  btn = gr.Button()
47
- outp=gr.Textbox()
 
48
  btn.click(run,None,outp)
49
  app.launch()
50
 
 
1
  import spaces
2
  import gradio as gr
3
+ #import transformers
4
+ #from transformers import AutoTokenizer
5
+ #from transformers import pipeline
6
+ from diffusers import StableDiffusionXLPipeline, UNet2DConditionModel, EulerDiscreteScheduler
7
+ from huggingface_hub import hf_hub_download
8
+ from safetensors.torch import load_file
9
 
10
+ base = "stabilityai/stable-diffusion-xl-base-1.0"
11
+ repo = "ByteDance/SDXL-Lightning"
12
+ ckpt = "sdxl_lightning_4step_unet.safetensors" # Use the correct ckpt for your step setting!
13
+
14
+ # Load model.
15
+ unet = UNet2DConditionModel.from_config(base, subfolder="unet").to("cuda", torch.float16)
16
+ unet.load_state_dict(load_file(hf_hub_download(repo, ckpt), device="cuda"))
17
+ pipe = StableDiffusionXLPipeline.from_pretrained(base, unet=unet, torch_dtype=torch.float16, variant="fp16").to("cuda")
18
+
19
+ # Ensure sampler uses "trailing" timesteps.
20
+ pipe.scheduler = EulerDiscreteScheduler.from_config(pipe.scheduler.config, timestep_spacing="trailing")
21
+
22
+ @spaces.GPU
23
+ def run():
24
+ # Ensure using the same inference steps as the loaded model and CFG set to 0.
25
+ return pipe("A cat", num_inference_steps=4, guidance_scale=0).images[0].save("output.png")
26
+
27
+
28
+
29
+
30
+ '''
31
  tokenizer = AutoTokenizer.from_pretrained("EleutherAI/gpt-neox-20b")
32
 
33
  model = transformers.AutoModelForCausalLM.from_pretrained(
 
55
  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."
56
  fmt_ex = PROMPT_FOR_GENERATION_FORMAT.format(instruction=example)
57
 
58
+
59
+
60
+
61
  @spaces.GPU
62
  def run():
63
  with torch.autocast('cuda', dtype=torch.bfloat16):
 
66
  max_new_tokens=100,
67
  do_sample=True,
68
  use_cache=True))
69
+ '''
70
 
71
 
72
  with gr.Blocks() as app:
73
  btn = gr.Button()
74
+ #outp=gr.Textbox()
75
+ outp=gr.Image()
76
  btn.click(run,None,outp)
77
  app.launch()
78