Update app.py
Browse files
app.py
CHANGED
@@ -1,33 +1,40 @@
|
|
1 |
import gradio as gr
|
2 |
import logging
|
3 |
-
import json
|
4 |
|
5 |
# Set up logging
|
6 |
logging.basicConfig(
|
7 |
-
level=logging.
|
8 |
)
|
9 |
logger = logging.getLogger(__name__)
|
10 |
|
|
|
|
|
11 |
|
12 |
-
def
|
13 |
-
|
14 |
-
|
|
|
|
|
|
|
|
|
|
|
15 |
|
|
|
16 |
with gr.Blocks() as demo:
|
17 |
-
|
18 |
-
gr.
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
|
27 |
-
|
|
|
28 |
|
29 |
-
|
30 |
-
# file_4.change(get_file_content, file_4, img)
|
31 |
|
32 |
if __name__ == "__main__":
|
33 |
-
demo.launch(debug=True)
|
|
|
1 |
import gradio as gr
|
2 |
import logging
|
|
|
3 |
|
4 |
# Set up logging
|
5 |
logging.basicConfig(
|
6 |
+
level=logging.DEBUG, format="%(asctime)s - %(levelname)s - %(message)s"
|
7 |
)
|
8 |
logger = logging.getLogger(__name__)
|
9 |
|
10 |
+
# Set the root directory as a reusable variable
|
11 |
+
ROOT_DIR = "./tmp"
|
12 |
|
13 |
+
def show_image(file_path):
|
14 |
+
logger.info(f"show_image function called with file_path: {file_path}")
|
15 |
+
if file_path:
|
16 |
+
result = file_path[0] if isinstance(file_path, list) else file_path
|
17 |
+
logger.info(f"Returning file path: {result}")
|
18 |
+
return result
|
19 |
+
logger.warning("No file path provided")
|
20 |
+
return None
|
21 |
|
22 |
+
logger.info("Starting Gradio app")
|
23 |
with gr.Blocks() as demo:
|
24 |
+
logger.info("Initializing FileExplorer component")
|
25 |
+
file_explorer = gr.FileExplorer(
|
26 |
+
glob="**/*.webp",
|
27 |
+
file_count="single",
|
28 |
+
root_dir=ROOT_DIR,
|
29 |
+
label="Select a WebP image"
|
30 |
+
)
|
31 |
+
logger.info("Initializing Image output component")
|
32 |
+
image_output = gr.Image(type="filepath", label="Selected Image")
|
33 |
|
34 |
+
logger.info("Setting up change event for FileExplorer")
|
35 |
+
file_explorer.change(show_image, inputs=file_explorer, outputs=image_output)
|
36 |
|
37 |
+
logger.info("Launching Gradio app")
|
|
|
38 |
|
39 |
if __name__ == "__main__":
|
40 |
+
demo.launch(debug=True)
|