Spaces:
Runtime error
Runtime error
Update app.py
Browse files
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.
|
| 14 |
img = Image.open(image_path)
|
| 15 |
-
img.thumbnail((512, 512)) #
|
| 16 |
-
temp_path = "
|
| 17 |
img.save(temp_path)
|
| 18 |
|
| 19 |
-
# 2.
|
| 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.
|
| 30 |
-
#
|
| 31 |
-
# [Image, Prompt, Image Relation, Lighting Preference]
|
| 32 |
try:
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
api_name="/predict" # Using the primary verified endpoint
|
| 40 |
)
|
| 41 |
-
return
|
| 42 |
except Exception as e:
|
| 43 |
-
#
|
| 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
|