Kalyankonga commited on
Commit
939b39a
·
verified ·
1 Parent(s): d8f140f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -22
app.py CHANGED
@@ -4,19 +4,27 @@ from PIL import Image
4
  import os
5
 
6
  # Connect to the verified IC-Light engine
7
- client = Client("lllyasviel/IC-Light") #
 
 
 
 
 
 
 
 
8
 
9
  def dynamic_relight(image_path, prompt, lighting_choice, s1, s2, s3, s4):
10
  if image_path is None:
11
  return None
12
 
13
- # 1. Image preparation
14
  img = Image.open(image_path)
15
- img.thumbnail((512, 512)) # Safety resize for remote processing
16
- temp_path = "final_fix.png"
17
  img.save(temp_path)
18
 
19
- # 2. Unique Project Feature: User-Desired Keyword Weighting
20
  keywords = ["cinematic", "detailed", "texture", "focus"]
21
  slider_vals = [s1, s2, s3, s4]
22
  weighted_prompt = prompt
@@ -24,30 +32,34 @@ def dynamic_relight(image_path, prompt, lighting_choice, s1, s2, s3, s4):
24
  weight = slider_vals[i] / 50.0
25
  weighted_prompt += f", ({word}:{weight:.1f})"
26
 
27
- # 3. FINAL ACCURATE CALL: Using fn_index=1
28
- # This targets the primary 'Relight' function in IC-Light
29
  try:
30
  result = client.predict(
31
- handle_file(temp_path), # input_fg
32
- weighted_prompt, # prompt
33
- "Appearance Variation", # image_relation
34
- lighting_choice, # lighting_preference
35
- fn_index=1 # Use numerical index to avoid ambiguity
 
 
 
 
 
 
 
 
 
 
36
  )
37
  return result[0]
38
  except Exception as e:
39
- # Emergency backup: If the Space updated, try fn_index=2
40
- return client.predict(
41
- handle_file(temp_path),
42
- weighted_prompt,
43
- "Appearance Variation",
44
- lighting_choice,
45
- fn_index=2
46
- )[0]
47
 
48
  # UI Setup
49
  with gr.Blocks() as demo:
50
- gr.Markdown("# 💡 Universal Feature Relighter")
51
  with gr.Row():
52
  with gr.Column():
53
  img = gr.Image(type="filepath", label="Input Image")
@@ -59,7 +71,7 @@ with gr.Blocks() as demo:
59
  s3 = gr.Slider(0, 100, value=50, label="Texture Sharpness")
60
  s4 = gr.Slider(0, 100, value=50, label="Focus Depth")
61
 
62
- btn = gr.Button("Execute Accurate Relighting", variant="primary")
63
  out = gr.Image(label="Output")
64
 
65
  btn.click(dynamic_relight, [img, txt, dirs, s1, s2, s3, s4], out)
 
4
  import os
5
 
6
  # Connect to the verified IC-Light engine
7
+ client = Client("lllyasviel/IC-Light")
8
+
9
+ # DIAGNOSTIC: This will print the EXACT API structure to your logs
10
+ print("--- FETCHING API STRUCTURE ---")
11
+ try:
12
+ print(client.view_api(return_format="str"))
13
+ except:
14
+ pass
15
+ print("------------------------------")
16
 
17
  def dynamic_relight(image_path, prompt, lighting_choice, s1, s2, s3, s4):
18
  if image_path is None:
19
  return None
20
 
21
+ # 1. Resize to verified safe dimensions (512x768 is the model's native ratio)
22
  img = Image.open(image_path)
23
+ img.thumbnail((512, 768))
24
+ temp_path = "safe_input.png"
25
  img.save(temp_path)
26
 
27
+ # 2. Your Unique Project Feature: Slider-Weighted Prompt
28
  keywords = ["cinematic", "detailed", "texture", "focus"]
29
  slider_vals = [s1, s2, s3, s4]
30
  weighted_prompt = prompt
 
32
  weight = slider_vals[i] / 50.0
33
  weighted_prompt += f", ({word}:{weight:.1f})"
34
 
35
+ # 3. THE FIX: Sending ALL 13 Required Arguments
36
+ # Based on the official repo's function signature
37
  try:
38
  result = client.predict(
39
+ handle_file(temp_path), # 1. input_fg
40
+ weighted_prompt, # 2. prompt
41
+ "Appearance Variation", # 3. image_relation (Relight)
42
+ lighting_choice, # 4. lighting_preference (Left/Right/etc)
43
+ 12345, # 5. seed (Required int)
44
+ 512, # 6. image_width
45
+ 768, # 7. image_height
46
+ 25, # 8. steps
47
+ 2.0, # 9. cfg_scale
48
+ 0.9, # 10. lowres_denoise
49
+ 1.5, # 11. highres_scale
50
+ 0.5, # 12. highres_denoise
51
+ "best quality", # 13. a_prompt (Added prompt)
52
+ "lowres, bad anatomy", # 14. n_prompt (Negative prompt)
53
+ fn_index=1 # Target the primary generation tab
54
  )
55
  return result[0]
56
  except Exception as e:
57
+ # Fallback: Prints the actual error if this precise payload fails
58
+ raise gr.Error(f"API Mismatch: {str(e)}")
 
 
 
 
 
 
59
 
60
  # UI Setup
61
  with gr.Blocks() as demo:
62
+ gr.Markdown("# 💡 Full-Parameter Feature Relighter")
63
  with gr.Row():
64
  with gr.Column():
65
  img = gr.Image(type="filepath", label="Input Image")
 
71
  s3 = gr.Slider(0, 100, value=50, label="Texture Sharpness")
72
  s4 = gr.Slider(0, 100, value=50, label="Focus Depth")
73
 
74
+ btn = gr.Button("Execute Relight", variant="primary")
75
  out = gr.Image(label="Output")
76
 
77
  btn.click(dynamic_relight, [img, txt, dirs, s1, s2, s3, s4], out)