huyai123 commited on
Commit
f4b717d
·
verified ·
1 Parent(s): 27e6396

Update handler.py

Browse files
Files changed (1) hide show
  1. handler.py +20 -8
handler.py CHANGED
@@ -5,13 +5,18 @@ from diffusers.utils import load_image
5
  from diffusers import FluxControlNetModel
6
  from diffusers.pipelines import FluxControlNetPipeline
7
  from io import BytesIO
 
8
 
9
  class EndpointHandler:
10
  def __init__(self, model_dir="huyai123/Flux.1-dev-Image-Upscaler"):
11
  # Access the environment variable
12
  HUGGINGFACE_API_TOKEN = os.getenv('HUGGINGFACE_API_TOKEN')
13
  if not HUGGINGFACE_API_TOKEN:
14
- raise ValueError("HUGGINGFACE_API_TOKEN")
 
 
 
 
15
 
16
  # Load model and pipeline
17
  self.controlnet = FluxControlNetModel.from_pretrained(
@@ -46,13 +51,20 @@ class EndpointHandler:
46
  # Preprocess input
47
  control_image = self.preprocess(data)
48
  # Generate output
49
- output_image = self.pipe(
50
- prompt=data.get("prompt", ""),
51
- control_image=control_image,
52
- controlnet_conditioning_scale=0.6,
53
  num_inference_steps=28,
54
- height=control_image.size[1],
55
- width=control_image.size[0],
56
  ).images[0]
57
  # Postprocess output
58
- return self.postprocess(output_image)
 
 
 
 
 
 
 
 
5
  from diffusers import FluxControlNetModel
6
  from diffusers.pipelines import FluxControlNetPipeline
7
  from io import BytesIO
8
+ import logging
9
 
10
  class EndpointHandler:
11
  def __init__(self, model_dir="huyai123/Flux.1-dev-Image-Upscaler"):
12
  # Access the environment variable
13
  HUGGINGFACE_API_TOKEN = os.getenv('HUGGINGFACE_API_TOKEN')
14
  if not HUGGINGFACE_API_TOKEN:
15
+ raise ValueError("HUGGINGFACE_API_TOKEN environment variable is not set")
16
+
17
+ # Log the token for debugging (remove this in production)
18
+ logging.basicConfig(level=logging.INFO)
19
+ logging.info(f"Using HUGGINGFACE_API_TOKEN: {HUGGINGFACE_API_TOKEN}")
20
 
21
  # Load model and pipeline
22
  self.controlnet = FluxControlNetModel.from_pretrained(
 
51
  # Preprocess input
52
  control_image = self.preprocess(data)
53
  # Generate output
54
+ outputImage = self.pipe(
55
+ prompt=data.get("prompt","),
56
+ control_image=controlImage,
57
+ controlnet_condition_scale=0.6,
58
  num_inference_steps=28,
59
+ height=controlImage.size[1],
60
+ width=controlImage.size[0],
61
  ).images[0]
62
  # Postprocess output
63
+ return self.postprocess(outputImage)
64
+
65
+ if __name__ == "__main__":
66
+ # Example usage
67
+ data = {'control_image': 'path/to/your/image.png', 'prompt': 'Your prompt here'}
68
+ handler = EndpointHandler()
69
+ output = handler.inference(data)
70
+ print(output)