Rachel7 commited on
Commit
bcf9eab
·
verified ·
1 Parent(s): 6b9578c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -27
app.py CHANGED
@@ -117,41 +117,54 @@ def answer_question(gallery):
117
  return f"An error occurred: {e}"
118
 
119
  #function for returning image with prompt
120
- def infer(prompt):
121
 
122
- seed = random.randint(0, MAX_SEED)
123
 
124
- generator = torch.Generator().manual_seed(seed)
125
  #prompt = 'ceramic mug with heart'
126
- image = pipe(
127
- prompt = 'create a mockup photo for an etsy listing. the product is '+prompt,
128
- guidance_scale = 0,
129
- num_inference_steps = 2,
130
- width = 512,
131
- height = 512,
132
- generator = generator
133
- ).images[0]
134
 
135
- return image
136
 
137
- device = "cuda" if torch.cuda.is_available() else "cpu"
138
 
139
- if torch.cuda.is_available():
140
- torch.cuda.max_memory_allocated(device=device)
141
- pipe = DiffusionPipeline.from_pretrained("stabilityai/sdxl-turbo", torch_dtype=torch.float16, variant="fp16", use_safetensors=True)
142
- pipe.enable_xformers_memory_efficient_attention()
143
- pipe = pipe.to(device)
144
- else:
145
- pipe = DiffusionPipeline.from_pretrained("stabilityai/sdxl-turbo", use_safetensors=True)
146
- pipe = pipe.to(device)
147
 
148
- MAX_SEED = np.iinfo(np.int32).max
149
- MAX_IMAGE_SIZE = 1024
 
 
 
 
 
 
 
 
 
 
 
 
 
150
  #now try it with gradio interface and upload gallery
151
- if torch.cuda.is_available():
152
- power_device = "GPU"
153
- else:
154
- power_device = "CPU"
 
 
 
 
155
  with gr.Blocks() as demo:
156
  title = gr.Markdown("""
157
  <div align="center">
 
117
  return f"An error occurred: {e}"
118
 
119
  #function for returning image with prompt
120
+ #def infer(prompt):
121
 
122
+ # seed = random.randint(0, MAX_SEED)
123
 
124
+ #generator = torch.Generator().manual_seed(seed)
125
  #prompt = 'ceramic mug with heart'
126
+ #image = pipe(
127
+ # prompt = 'create a mockup photo for an etsy listing. the product is '+prompt,
128
+ # guidance_scale = 0,
129
+ # num_inference_steps = 2,
130
+ # width = 512,
131
+ # height = 512,
132
+ # generator = generator
133
+ # ).images[0]
134
 
135
+ # return image
136
 
 
137
 
138
+ def infer(prompt):
139
+
140
+ image = pipeline(
141
+ prompt = 'create a mockup photo for an etsy listing. the product is '+prompt
142
+ ).images[0]
 
 
 
143
 
144
+ return image
145
+
146
+ #device = "cuda" if torch.cuda.is_available() else "cpu"
147
+
148
+ #if torch.cuda.is_available():
149
+ # torch.cuda.max_memory_allocated(device=device)
150
+ # pipe = DiffusionPipeline.from_pretrained("stabilityai/sdxl-turbo", torch_dtype=torch.float16, variant="fp16", use_safetensors=True)
151
+ # pipe.enable_xformers_memory_efficient_attention()
152
+ # pipe = pipe.to(device)
153
+ #else:
154
+ # pipe = DiffusionPipeline.from_pretrained("stabilityai/sdxl-turbo", use_safetensors=True)
155
+ # pipe = pipe.to(device)
156
+
157
+ #MAX_SEED = np.iinfo(np.int32).max
158
+ #MAX_IMAGE_SIZE = 1024
159
  #now try it with gradio interface and upload gallery
160
+ #if torch.cuda.is_available():
161
+ # power_device = "GPU"
162
+ #else:
163
+ # power_device = "CPU"
164
+
165
+ pipeline = DiffusionPipeline.from_pretrained("runwayml/stable-diffusion-v1-5", torch_dtype=torch.float16)
166
+ pipeline.to("cuda")
167
+
168
  with gr.Blocks() as demo:
169
  title = gr.Markdown("""
170
  <div align="center">