Update apps/gradio_app.py
Browse files- apps/gradio_app.py +37 -9
apps/gradio_app.py
CHANGED
@@ -1,5 +1,6 @@
|
|
1 |
import gradio as gr
|
2 |
import os
|
|
|
3 |
from gradio_app.config import setup_logging, setup_sys_path
|
4 |
from gradio_app.processor import gradio_process, update_preview, update_visibility
|
5 |
|
@@ -7,8 +8,21 @@ from gradio_app.processor import gradio_process, update_preview, update_visibili
|
|
7 |
setup_logging()
|
8 |
setup_sys_path()
|
9 |
|
|
|
|
|
|
|
10 |
# Load custom CSS
|
11 |
-
custom_css =
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
|
13 |
# Path to examples directory
|
14 |
examples_dir = os.path.join(os.path.dirname(__file__), "gradio_app", "assets", "examples", "license_plate_detector_ocr")
|
@@ -27,13 +41,27 @@ examples = [
|
|
27 |
}
|
28 |
]
|
29 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
30 |
# Function to handle example selection
|
31 |
def select_example(selected_row, examples_data):
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
37 |
|
38 |
# Gradio Interface
|
39 |
with gr.Blocks(css=custom_css) as iface:
|
@@ -48,7 +76,7 @@ with gr.Blocks(css=custom_css) as iface:
|
|
48 |
|
49 |
with gr.Row():
|
50 |
with gr.Column(scale=1):
|
51 |
-
input_file = gr.File(label="Upload Image or Video", elem_classes="custom-file-input")
|
52 |
input_type = gr.Radio(choices=["Image", "Video"], label="Input Type", value="Image", elem_classes="custom-radio")
|
53 |
with gr.Blocks():
|
54 |
input_preview_image = gr.Image(label="Input Preview", visible=True, elem_classes="custom-image")
|
@@ -60,7 +88,7 @@ with gr.Blocks(css=custom_css) as iface:
|
|
60 |
# Examples table
|
61 |
gr.Markdown("### Examples")
|
62 |
examples_table = gr.Dataframe(
|
63 |
-
value=[[ex["Input File"], ex["Output File"], ex["Input Type"]] for ex in examples],
|
64 |
headers=["Input File", "Output File", "Input Type"],
|
65 |
interactive=True, # Allow row selection
|
66 |
elem_classes="custom-table"
|
@@ -107,4 +135,4 @@ with gr.Blocks(css=custom_css) as iface:
|
|
107 |
)
|
108 |
|
109 |
if __name__ == "__main__":
|
110 |
-
iface.launch(
|
|
|
1 |
import gradio as gr
|
2 |
import os
|
3 |
+
import logging
|
4 |
from gradio_app.config import setup_logging, setup_sys_path
|
5 |
from gradio_app.processor import gradio_process, update_preview, update_visibility
|
6 |
|
|
|
8 |
setup_logging()
|
9 |
setup_sys_path()
|
10 |
|
11 |
+
# Configure logging
|
12 |
+
logger = logging.getLogger(__name__)
|
13 |
+
|
14 |
# Load custom CSS
|
15 |
+
custom_css = """
|
16 |
+
.custom-table tr:hover { background-color: #f0f0f0; cursor: pointer; }
|
17 |
+
.custom-table .selected { background-color: #d0e8ff; }
|
18 |
+
.custom-file-input { margin-bottom: 10px; }
|
19 |
+
.custom-radio { margin-bottom: 10px; }
|
20 |
+
.custom-button { margin: 5px; }
|
21 |
+
.custom-image, .custom-video { width: 100%; }
|
22 |
+
.custom-textbox { width: 100%; }
|
23 |
+
"""
|
24 |
+
# Optionally, you can still load from styles.css if preferred
|
25 |
+
# custom_css = open(os.path.join(os.path.dirname(__file__), "gradio_app", "static", "styles.css"), "r").read()
|
26 |
|
27 |
# Path to examples directory
|
28 |
examples_dir = os.path.join(os.path.dirname(__file__), "gradio_app", "assets", "examples", "license_plate_detector_ocr")
|
|
|
41 |
}
|
42 |
]
|
43 |
|
44 |
+
# Validate example file paths
|
45 |
+
for ex in examples:
|
46 |
+
if not os.path.exists(ex["Input File"]):
|
47 |
+
logger.error(f"Input file not found: {ex['Input File']}")
|
48 |
+
if not os.path.exists(ex["Output File"]):
|
49 |
+
logger.error(f"Output file not found: {ex['Output File']}")
|
50 |
+
|
51 |
# Function to handle example selection
|
52 |
def select_example(selected_row, examples_data):
|
53 |
+
logger.info(f"Selected row: {selected_row}")
|
54 |
+
if selected_row is not None:
|
55 |
+
try:
|
56 |
+
row_index = int(selected_row[0]) if isinstance(selected_row, list) else int(selected_row)
|
57 |
+
if 0 <= row_index < len(examples):
|
58 |
+
selected_example = examples[row_index]
|
59 |
+
input_file_path = selected_example["Input File"]
|
60 |
+
logger.info(f"Loading file: {input_file_path}")
|
61 |
+
return input_file_path, selected_example["Input Type"], None, None, None
|
62 |
+
except (IndexError, ValueError, TypeError) as e:
|
63 |
+
logger.error(f"Error selecting example: {e}")
|
64 |
+
return None, "Image", None, None, None # Default return if selection fails
|
65 |
|
66 |
# Gradio Interface
|
67 |
with gr.Blocks(css=custom_css) as iface:
|
|
|
76 |
|
77 |
with gr.Row():
|
78 |
with gr.Column(scale=1):
|
79 |
+
input_file = gr.File(label="Upload Image or Video", file_types=["image", "video"], elem_classes="custom-file-input")
|
80 |
input_type = gr.Radio(choices=["Image", "Video"], label="Input Type", value="Image", elem_classes="custom-radio")
|
81 |
with gr.Blocks():
|
82 |
input_preview_image = gr.Image(label="Input Preview", visible=True, elem_classes="custom-image")
|
|
|
88 |
# Examples table
|
89 |
gr.Markdown("### Examples")
|
90 |
examples_table = gr.Dataframe(
|
91 |
+
value=[[os.path.basename(ex["Input File"]), os.path.basename(ex["Output File"]), ex["Input Type"]] for ex in examples],
|
92 |
headers=["Input File", "Output File", "Input Type"],
|
93 |
interactive=True, # Allow row selection
|
94 |
elem_classes="custom-table"
|
|
|
135 |
)
|
136 |
|
137 |
if __name__ == "__main__":
|
138 |
+
iface.launch()
|