Hermes Bot commited on
Commit ·
26f5a9f
1
Parent(s): 1521e96
Add drag-and-drop info upload component and handler
Browse files- ui/events/run_handlers.py +19 -0
- ui/layout.py +3 -0
ui/events/run_handlers.py
CHANGED
|
@@ -2,6 +2,22 @@ import gradio as gr
|
|
| 2 |
import os
|
| 3 |
from core.generation_logic import generate_image_wrapper
|
| 4 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
def create_run_event(prefix: str, task_type: str, ui_components: dict):
|
| 6 |
run_inputs_map = {
|
| 7 |
'model_display_name': ui_components[f'base_model_{prefix}'],
|
|
@@ -142,3 +158,6 @@ def create_run_event(prefix: str, task_type: str, ui_components: dict):
|
|
| 142 |
# Auto metadata extraction on gallery selection removed.
|
| 143 |
# Users can now drag‑and‑drop an image onto the "Drag image here for info" component
|
| 144 |
# to view its generation info.
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
import os
|
| 3 |
from core.generation_logic import generate_image_wrapper
|
| 4 |
|
| 5 |
+
def _show_meta_file(file_path):
|
| 6 |
+
"""Extract metadata from the uploaded image file.
|
| 7 |
+
For now returns a placeholder if extraction fails.
|
| 8 |
+
"""
|
| 9 |
+
try:
|
| 10 |
+
from PIL import Image
|
| 11 |
+
img = Image.open(file_path)
|
| 12 |
+
info = img.info
|
| 13 |
+
# Build a simple key: value string
|
| 14 |
+
lines = []
|
| 15 |
+
for k, v in info.items():
|
| 16 |
+
lines.append(f"{k}: {v}")
|
| 17 |
+
return "\n".join(lines) if lines else "(ไม่มีข้อมูลเมตาดาต้า)"
|
| 18 |
+
except Exception:
|
| 19 |
+
return "(ไม่มีข้อมูลเมตาดาต้า)"
|
| 20 |
+
|
| 21 |
def create_run_event(prefix: str, task_type: str, ui_components: dict):
|
| 22 |
run_inputs_map = {
|
| 23 |
'model_display_name': ui_components[f'base_model_{prefix}'],
|
|
|
|
| 158 |
# Auto metadata extraction on gallery selection removed.
|
| 159 |
# Users can now drag‑and‑drop an image onto the "Drag image here for info" component
|
| 160 |
# to view its generation info.
|
| 161 |
+
info_upload = ui_components.get('info_upload')
|
| 162 |
+
if info_upload:
|
| 163 |
+
info_upload.change(fn=_show_meta_file, inputs=info_upload, outputs=ui_components.get('gallery_metadata'))
|
ui/layout.py
CHANGED
|
@@ -109,6 +109,9 @@ def build_ui(event_handler_function):
|
|
| 109 |
# Textbox to show generation info for selected image.
|
| 110 |
metadata_box = gr.Textbox(label="Generation info", lines=4, interactive=False)
|
| 111 |
ui_components["gallery_metadata"] = metadata_box
|
|
|
|
|
|
|
|
|
|
| 112 |
# Hidden file component for zip download.
|
| 113 |
download_file = gr.File(label="Download", visible=False)
|
| 114 |
# Bind buttons.
|
|
|
|
| 109 |
# Textbox to show generation info for selected image.
|
| 110 |
metadata_box = gr.Textbox(label="Generation info", lines=4, interactive=False)
|
| 111 |
ui_components["gallery_metadata"] = metadata_box
|
| 112 |
+
# Drag-and-drop file component for extracting generation info.
|
| 113 |
+
info_upload = gr.File(label="Drag image here for info", file_count="single", type="filepath")
|
| 114 |
+
ui_components["info_upload"] = info_upload
|
| 115 |
# Hidden file component for zip download.
|
| 116 |
download_file = gr.File(label="Download", visible=False)
|
| 117 |
# Bind buttons.
|