update app [.]
Browse files
app.py
CHANGED
|
@@ -12,7 +12,6 @@ from typing import Iterable
|
|
| 12 |
from gradio.themes import Soft
|
| 13 |
from gradio.themes.utils import colors, fonts, sizes
|
| 14 |
|
| 15 |
-
# Rerun imports
|
| 16 |
import rerun as rr
|
| 17 |
from gradio_rerun import Rerun
|
| 18 |
|
|
@@ -220,38 +219,24 @@ def infer(
|
|
| 220 |
|
| 221 |
run_id = str(uuid.uuid4())
|
| 222 |
|
| 223 |
-
#
|
| 224 |
rec = None
|
| 225 |
if hasattr(rr, "new_recording"):
|
|
|
|
| 226 |
rec = rr.new_recording(application_id="Qwen-Image-Edit", recording_id=run_id)
|
| 227 |
elif hasattr(rr, "RecordingStream"):
|
|
|
|
| 228 |
rec = rr.RecordingStream(application_id="Qwen-Image-Edit", recording_id=run_id)
|
| 229 |
else:
|
|
|
|
| 230 |
rr.init("Qwen-Image-Edit", recording_id=run_id, spawn=False)
|
| 231 |
rec = rr
|
| 232 |
|
| 233 |
-
#
|
|
|
|
| 234 |
rec.log("images/original", rr.Image(np.array(original_image)))
|
| 235 |
-
|
| 236 |
-
# 2. Log Edited Image
|
| 237 |
rec.log("images/edited", rr.Image(np.array(result_image)))
|
| 238 |
|
| 239 |
-
# 3. Create Download Link inside Rerun
|
| 240 |
-
# Save the result image to disk so Gradio can serve it
|
| 241 |
-
save_filename = f"edited_{run_id}.png"
|
| 242 |
-
save_path = os.path.join(TMP_DIR, save_filename)
|
| 243 |
-
result_image.save(save_path)
|
| 244 |
-
|
| 245 |
-
# Create a markdown link pointing to the file served by Gradio
|
| 246 |
-
# /file= is the standard Gradio route for serving local files
|
| 247 |
-
download_markdown = f"""
|
| 248 |
-
# Download
|
| 249 |
-
[Click here to download the edited image](/file={save_path})
|
| 250 |
-
"""
|
| 251 |
-
|
| 252 |
-
# Log the markdown document
|
| 253 |
-
rec.log("download_section", rr.TextDocument(download_markdown, media_type=rr.MediaType.MARKDOWN))
|
| 254 |
-
|
| 255 |
# Save RRD
|
| 256 |
rrd_path = os.path.join(TMP_DIR, f"{run_id}.rrd")
|
| 257 |
rec.save(rrd_path)
|
|
@@ -272,7 +257,7 @@ def infer_example(input_image, prompt, lora_adapter):
|
|
| 272 |
input_pil = input_image.convert("RGB")
|
| 273 |
guidance_scale = 1.0
|
| 274 |
steps = 4
|
| 275 |
-
# Call main infer but ignore progress for examples
|
| 276 |
result_rrd, seed = infer(input_pil, prompt, lora_adapter, 0, True, guidance_scale, steps)
|
| 277 |
return result_rrd, seed
|
| 278 |
|
|
@@ -302,7 +287,7 @@ with gr.Blocks() as demo:
|
|
| 302 |
run_button = gr.Button("Edit Image", variant="primary")
|
| 303 |
|
| 304 |
with gr.Column():
|
| 305 |
-
# Rerun Viewer
|
| 306 |
rerun_output = Rerun(
|
| 307 |
label="Rerun Visualization",
|
| 308 |
height=353
|
|
|
|
| 12 |
from gradio.themes import Soft
|
| 13 |
from gradio.themes.utils import colors, fonts, sizes
|
| 14 |
|
|
|
|
| 15 |
import rerun as rr
|
| 16 |
from gradio_rerun import Rerun
|
| 17 |
|
|
|
|
| 219 |
|
| 220 |
run_id = str(uuid.uuid4())
|
| 221 |
|
| 222 |
+
# Handle different Rerun SDK versions robustly
|
| 223 |
rec = None
|
| 224 |
if hasattr(rr, "new_recording"):
|
| 225 |
+
# Newer Rerun versions
|
| 226 |
rec = rr.new_recording(application_id="Qwen-Image-Edit", recording_id=run_id)
|
| 227 |
elif hasattr(rr, "RecordingStream"):
|
| 228 |
+
# Alternative direct class instantiation
|
| 229 |
rec = rr.RecordingStream(application_id="Qwen-Image-Edit", recording_id=run_id)
|
| 230 |
else:
|
| 231 |
+
# Fallback for older versions or simple scripts (Global State)
|
| 232 |
rr.init("Qwen-Image-Edit", recording_id=run_id, spawn=False)
|
| 233 |
rec = rr
|
| 234 |
|
| 235 |
+
# Log images to Rerun
|
| 236 |
+
# rec.log handles logging for both RecordingStream objects and the global rr module
|
| 237 |
rec.log("images/original", rr.Image(np.array(original_image)))
|
|
|
|
|
|
|
| 238 |
rec.log("images/edited", rr.Image(np.array(result_image)))
|
| 239 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 240 |
# Save RRD
|
| 241 |
rrd_path = os.path.join(TMP_DIR, f"{run_id}.rrd")
|
| 242 |
rec.save(rrd_path)
|
|
|
|
| 257 |
input_pil = input_image.convert("RGB")
|
| 258 |
guidance_scale = 1.0
|
| 259 |
steps = 4
|
| 260 |
+
# Call main infer but ignore progress for examples if needed
|
| 261 |
result_rrd, seed = infer(input_pil, prompt, lora_adapter, 0, True, guidance_scale, steps)
|
| 262 |
return result_rrd, seed
|
| 263 |
|
|
|
|
| 287 |
run_button = gr.Button("Edit Image", variant="primary")
|
| 288 |
|
| 289 |
with gr.Column():
|
| 290 |
+
# Replaced standard Image with Rerun Viewer
|
| 291 |
rerun_output = Rerun(
|
| 292 |
label="Rerun Visualization",
|
| 293 |
height=353
|