Spaces:
Runtime error
Runtime error
Update app.py
Browse files
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.
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
for i,
|
| 13 |
-
|
| 14 |
-
|
|
|
|
| 15 |
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 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 |
|