Kalyankonga commited on
Commit
d8f140f
·
verified ·
1 Parent(s): 8b18861

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -19
app.py CHANGED
@@ -10,42 +10,39 @@ def dynamic_relight(image_path, prompt, lighting_choice, s1, s2, s3, s4):
10
  if image_path is None:
11
  return None
12
 
13
- # 1. SAFETY: Resize image to prevent remote server timeout
14
  img = Image.open(image_path)
15
- img.thumbnail((512, 512)) # Smaller size ensures higher success rate
16
- temp_path = "final_test_input.png"
17
  img.save(temp_path)
18
 
19
- # 2. PROPOSED SYSTEM: User-Desired Keyword Weighting
20
- # This creates the 'Unique' project logic you proposed
21
  keywords = ["cinematic", "detailed", "texture", "focus"]
22
  slider_vals = [s1, s2, s3, s4]
23
-
24
  weighted_prompt = prompt
25
  for i, word in enumerate(keywords):
26
  weight = slider_vals[i] / 50.0
27
  weighted_prompt += f", ({word}:{weight:.1f})"
28
 
29
- # 3. ROBUST EXECUTION: Positional Call
30
- # By analyzing the IC-Light API, the standard input sequence is:
31
- # [Image, Prompt, Image Relation, Lighting Preference]
32
  try:
33
- # We pass arguments as a list to match the remote API schema exactly
34
- job = client.submit(
35
- handle_file(temp_path),
36
- weighted_prompt,
37
- "Appearance Variation", # image_relation
38
- lighting_choice, # lighting_preference
39
- api_name="/predict" # Using the primary verified endpoint
40
  )
41
- return job.result()[0]
42
  except Exception as e:
43
- # Fallback to the most basic execution possible
44
  return client.predict(
45
  handle_file(temp_path),
46
  weighted_prompt,
47
  "Appearance Variation",
48
- lighting_choice
 
49
  )[0]
50
 
51
  # UI Setup
 
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
23
  for i, word in enumerate(keywords):
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