Create api running requirements

#69
by JinsBenny - opened
Files changed (1) hide show
  1. api running requirements +41 -0
api running requirements ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Things to be added and adjusted in running API based iclight V2 on Gradio
2
+ # try to adjust the width and height dynamically as per input image
3
+
4
+ # Open and verify the image
5
+ img = Image.open(image_path)
6
+ img.verify() # Verify integrity
7
+ width, height = img.size
8
+ print("Width:", width,"\nHeight:", height)
9
+
10
+
11
+ # Use handle_file when importing image using its path
12
+ # Needs to be imported from gradio_client
13
+
14
+ from gradio_client import handle_file
15
+
16
+ # Initialize Gradio client with error handling
17
+ client = Client("lllyasviel/iclight-v2")
18
+ # To inspect the Gradio API to see what endpoints are available
19
+ print(client.view_api())
20
+
21
+ result = client.predict(
22
+ input_fg=handle_file(image_path),
23
+ bg_source="None",
24
+ prompt=prompt,
25
+ image_width=float(width),
26
+ image_height=float(height),
27
+ num_samples=1,
28
+ seed=12345,
29
+ steps=25,
30
+ n_prompt="",
31
+ cfg=1,
32
+ gs=5,
33
+ rs=1,
34
+ init_denoise=0.999,
35
+ api_name="/process"
36
+ )
37
+
38
+ # The result is a tuple: (outputs, preprocessed_foreground)
39
+ output_image = result[0]
40
+ masked_image = results[1]
41
+