Kalyankonga commited on
Commit
aab5ea1
·
verified ·
1 Parent(s): 259188b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -18
app.py CHANGED
@@ -1,30 +1,38 @@
1
  import gradio as gr
2
  from gradio_client import Client, handle_file
3
  import PIL.Image
 
4
 
5
  # Connect to the verified IC-Light engine
6
  client = Client("lllyasviel/IC-Light") # cite: 5.3
7
 
8
  def dynamic_relight(image, prompt, lighting_choice, *slider_values):
9
- # 1. Your unique weighted prompt logic
10
- features = ["cinematic", "detailed", "texture", "focus"]
11
- weighted_parts = []
12
- for i, feature in enumerate(features):
13
- weight = slider_values[i] / 50
14
- weighted_parts.append(f"({feature}:{weight:.1f})")
 
15
 
16
- final_prompt = f"{prompt}, " + ", ".join(weighted_parts)
17
-
18
- # 2. ACCURATE client.predict call
19
- # We use fn_index=1 to bypass the missing api_name error
20
- # This is the most stable way to call complex remote Spaces
21
- result = client.predict(
22
- handle_file(image), # input_fg
23
- final_prompt, # prompt
24
- "Appearance Variation", # image_relation
25
- lighting_choice, # lighting_preference
26
- fn_index=1 # Use numerical index for stability
27
- )
 
 
 
 
 
 
28
 
29
  return result[0]
30
 
 
1
  import gradio as gr
2
  from gradio_client import Client, handle_file
3
  import PIL.Image
4
+ import re
5
 
6
  # Connect to the verified IC-Light engine
7
  client = Client("lllyasviel/IC-Light") # cite: 5.3
8
 
9
  def dynamic_relight(image, prompt, lighting_choice, *slider_values):
10
+ # 1. Map Sliders to Prompt Keywords (Your unique feature)
11
+ keywords = ["cinematic", "detailed", "texture", "focus"]
12
+ weighted_prompt = prompt
13
+ for i, word in enumerate(keywords):
14
+ if i < len(slider_values):
15
+ weight = slider_values[i] / 50.0
16
+ weighted_prompt += f", ({word}:{weight:.1f})"
17
 
18
+ # 2. Use the correct positional order as defined by IC-Light
19
+ # For IC-Light, the order is typically: image, prompt, relation, preference
20
+ try:
21
+ result = client.predict(
22
+ input_fg=handle_file(image),
23
+ prompt=weighted_prompt,
24
+ image_relation="Appearance Variation",
25
+ lighting_preference=lighting_choice,
26
+ api_name="/relight" # Attempting named API first
27
+ )
28
+ except Exception:
29
+ # Fallback to positional arguments if named API fails
30
+ result = client.predict(
31
+ handle_file(image),
32
+ weighted_prompt,
33
+ "Appearance Variation",
34
+ lighting_choice
35
+ )
36
 
37
  return result[0]
38