Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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. Identify keywords from your project prompt
|
| 10 |
+
features = ["cinematic", "detailed", "texture", "focus"]
|
| 11 |
+
|
| 12 |
+
# 2. Build a weighted prompt based on your SLIDERS
|
| 13 |
+
weighted_parts = []
|
| 14 |
+
for i, feature in enumerate(features):
|
| 15 |
+
weight = slider_values[i] / 50 # Convert 0-100 to 0.0-2.0
|
| 16 |
+
weighted_parts.append(f"({feature}:{weight:.1f})")
|
| 17 |
+
|
| 18 |
+
final_prompt = f"{prompt}, " + ", ".join(weighted_parts)
|
| 19 |
+
|
| 20 |
+
# 3. Execute the request to the high-end hardware
|
| 21 |
+
# This ensures accuracy without crashing your own session
|
| 22 |
+
result = client.predict(
|
| 23 |
+
input_fg=handle_file(image),
|
| 24 |
+
prompt=final_prompt,
|
| 25 |
+
image_relation="Appearance Variation",
|
| 26 |
+
lighting_preference=lighting_choice,
|
| 27 |
+
api_name="/relight"
|
| 28 |
+
)
|
| 29 |
+
|
| 30 |
+
# Result[0] is typically the main relit image
|
| 31 |
+
return result[0]
|
| 32 |
+
|
| 33 |
+
with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
| 34 |
+
gr.Markdown("# 💡 My Unique Project: Dynamic Feature Relighter")
|
| 35 |
+
|
| 36 |
+
with gr.Row():
|
| 37 |
+
with gr.Column():
|
| 38 |
+
input_img = gr.Image(type="filepath", label="Input Image")
|
| 39 |
+
user_prompt = gr.Textbox(label="Base Prompt", value="A professional portrait")
|
| 40 |
+
light_pref = gr.Radio(["Left Light", "Right Light", "Top Light", "Bottom Light"], label="Light Direction", value="Left Light")
|
| 41 |
+
|
| 42 |
+
gr.Markdown("### User-Desired Feature Adjustments")
|
| 43 |
+
s1 = gr.Slider(0, 100, value=50, label="Cinematic Intensity")
|
| 44 |
+
s2 = gr.Slider(0, 100, value=50, label="Detail Level")
|
| 45 |
+
s3 = gr.Slider(0, 100, value=50, label="Skin Texture Sharpness")
|
| 46 |
+
s4 = gr.Slider(0, 100, value=50, label="Focus Depth")
|
| 47 |
+
|
| 48 |
+
run_btn = gr.Button("Execute Relighting", variant="primary")
|
| 49 |
+
|
| 50 |
+
with gr.Column():
|
| 51 |
+
output_img = gr.Image(label="Accurate AI Output")
|
| 52 |
+
|
| 53 |
+
run_btn.click(
|
| 54 |
+
fn=dynamic_relight,
|
| 55 |
+
inputs=[input_img, user_prompt, light_pref, s1, s2, s3, s4],
|
| 56 |
+
outputs=output_img
|
| 57 |
+
)
|
| 58 |
+
|
| 59 |
+
demo.launch()
|