davidberenstein1957 HF staff commited on
Commit
f364bfe
1 Parent(s): add5a0b

Update handler.py

Browse files

the following input is send to the endpoint with a post request.
```
{'json': {'inputs': 'a dog waiting for its companion to come.', 'parameters': {'negative_prompt': 'no dog', 'height': 512, 'width': 512, 'num_inference_steps': 25, 'guidance_scale': 7.5}}}
```

Files changed (1) hide show
  1. handler.py +12 -6
handler.py CHANGED
@@ -9,15 +9,21 @@ class EndpointHandler:
9
  ).to("cuda")
10
 
11
  def __call__(self, data: Dict[str, Any]) -> List[Dict[str, Any]]:
12
- inputs = data.pop("inputs")
13
- prompt = inputs.pop("prompt", "dog")
14
- guidance_scale = inputs.pop("guidance_scale", 4.5)
15
- num_inference_steps = inputs.pop("num_inference_steps", 28)
16
- seed = inputs.pop("seed", 0)
 
 
 
 
17
 
18
  prediction = self.pipeline(
19
  prompt,
20
- negative_prompt="bad quality, worse quality, deformed",
 
 
21
  guidance_scale=guidance_scale,
22
  num_inference_steps=num_inference_steps,
23
  generator=torch.manual_seed(seed)
 
9
  ).to("cuda")
10
 
11
  def __call__(self, data: Dict[str, Any]) -> List[Dict[str, Any]]:
12
+ data = data.pop("json")
13
+ prompt = data.pop("inputs", None)
14
+ parameters = data.pop("parameters", {})
15
+ negative_prompt = parameters.pop("negative_prompt", "bad quality, worse quality, deformed")
16
+ height = parameters.pop("height", 512)
17
+ width = parameters.pop("width", 512)
18
+ guidance_scale = parameters.pop("guidance_scale", 4.5)
19
+ num_inference_steps = parameters.pop("num_inference_steps", 28)
20
+ seed = parameters.pop("seed", 0)
21
 
22
  prediction = self.pipeline(
23
  prompt,
24
+ negative_prompt=negative_prompt,
25
+ height=height,
26
+ width=width,
27
  guidance_scale=guidance_scale,
28
  num_inference_steps=num_inference_steps,
29
  generator=torch.manual_seed(seed)