xpvwklvjp commited on
Commit
6c9bc25
·
verified ·
1 Parent(s): bef9af6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -18
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.INFO, format="%(asctime)s - %(levelname)s - %(message)s"
8
  )
9
  logger = logging.getLogger(__name__)
10
 
 
 
11
 
12
- def get_file_content(file):
13
- return (file,)
14
-
 
 
 
 
 
15
 
 
16
  with gr.Blocks() as demo:
17
- gr.Markdown("---")
18
- gr.Markdown('### `FileExplorer` to `Image` "`')
19
- with gr.Group():
20
- with gr.Row():
21
- file_4 = gr.FileExplorer(
22
- scale=1,
23
- file_count="single",
24
- elem_id="file",
25
- )
26
 
27
- img = gr.Image(scale=2)
 
28
 
29
- file_4.change(logger.info(json.dumps(get_file_content)))
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)