debisoft commited on
Commit
3f89984
1 Parent(s): 275a9c1
Files changed (1) hide show
  1. app.py +25 -6
app.py CHANGED
@@ -122,17 +122,36 @@ ab_t[0] = 1
122
  # construct model
123
  nn_model = ContextUnet(in_channels=3, n_feat=n_feat, n_cfeat=n_cfeat, height=height).to(device)
124
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
125
  def greet(input):
126
- prompt = f"""
127
- Recommend complementary shop combinations which match well with the shop(s) described in the following text, which is delimited by triple backticks. Rank by synergy: \
128
- Text: ```{input}```
129
- """
130
- response = prompt
131
  return response
132
 
133
  #iface = gr.Interface(fn=greet, inputs="text", outputs="text")
134
  #iface.launch()
135
 
136
  #iface = gr.Interface(fn=greet, inputs=[gr.Textbox(label="Text to find entities", lines=2)], outputs=[gr.HighlightedText(label="Text with entities")], title="NER with dslim/bert-base-NER", description="Find entities using the `dslim/bert-base-NER` model under the hood!", allow_flagging="never", examples=["My name is Andrew and I live in California", "My name is Poli and work at HuggingFace"])
137
- iface = gr.Interface(fn=greet, inputs=[gr.Textbox(label="Co-Retailing Business")], outputs="text")
138
  iface.launch()
 
122
  # construct model
123
  nn_model = ContextUnet(in_channels=3, n_feat=n_feat, n_cfeat=n_cfeat, height=height).to(device)
124
 
125
+ # sample quickly using DDIM
126
+ @torch.no_grad()
127
+ def sample_ddim(n_sample, n=20):
128
+ # x_T ~ N(0, 1), sample initial noise
129
+ samples = torch.randn(n_sample, 3, height, height).to(device)
130
+
131
+ # array to keep track of generated steps for plotting
132
+ intermediate = []
133
+ step_size = timesteps // n
134
+ for i in range(timesteps, 0, -step_size):
135
+ print(f'sampling timestep {i:3d}', end='\r')
136
+
137
+ # reshape time tensor
138
+ t = torch.tensor([i / timesteps])[:, None, None, None].to(device)
139
+
140
+ eps = nn_model(samples, t) # predict noise e_(x_t,t)
141
+ samples = denoise_ddim(samples, i, i - step_size, eps)
142
+ intermediate.append(samples.detach().cpu().numpy())
143
+
144
+ intermediate = np.stack(intermediate)
145
+ return samples, intermediate
146
+
147
  def greet(input):
148
+ samples, intermediate = sample_ddim(32, n=25)
149
+ response = intermediate[-1]
 
 
 
150
  return response
151
 
152
  #iface = gr.Interface(fn=greet, inputs="text", outputs="text")
153
  #iface.launch()
154
 
155
  #iface = gr.Interface(fn=greet, inputs=[gr.Textbox(label="Text to find entities", lines=2)], outputs=[gr.HighlightedText(label="Text with entities")], title="NER with dslim/bert-base-NER", description="Find entities using the `dslim/bert-base-NER` model under the hood!", allow_flagging="never", examples=["My name is Andrew and I live in California", "My name is Poli and work at HuggingFace"])
156
+ iface = gr.Interface(fn=greet, inputs=[gr.Textbox(label="Co-Retailing Business")], outputs="image")
157
  iface.launch()