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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +56 -12
app.py CHANGED
@@ -10,29 +10,73 @@ logger = logging.getLogger(__name__)
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
 
 
10
  # Set the root directory as a reusable variable
11
  ROOT_DIR = "./tmp"
12
 
13
+ # Set a password for file explorer access
14
+ FILE_EXPLORER_PASSWORD = "secret123" # You should use a more secure password in a real application
15
+
16
  def show_image(file_path):
17
  logger.info(f"show_image function called with file_path: {file_path}")
18
  if file_path:
19
  result = file_path[0] if isinstance(file_path, list) else file_path
20
  logger.info(f"Returning file path: {result}")
21
+ return result, f"Selected image: {result}"
22
  logger.warning("No file path provided")
23
+ return None, "No image selected"
24
+
25
+ def generate_image(prompt):
26
+ # Placeholder for the actual image generation function
27
+ logger.info(f"generate_image function called with prompt: {prompt}")
28
+ return None, f"Image would be generated based on the prompt: {prompt}"
29
+
30
+ def check_seed(seed):
31
+ logger.info("Seed check initiated")
32
+ if seed == FILE_EXPLORER_PASSWORD:
33
+ logger.info("Correct seed entered")
34
+ return gr.update(visible=True)
35
+ else:
36
+ logger.info("Incorrect seed entered")
37
+ return gr.update(visible=False)
38
 
39
  logger.info("Starting Gradio app")
40
  with gr.Blocks() as demo:
41
+ gr.Markdown("# Text-to-Image Generation and File Explorer")
42
+ gr.Markdown("Enter a prompt to generate an image or enter the correct seed to access additional features.")
43
+
44
+ with gr.Row():
45
+ with gr.Column(scale=1):
46
+ prompt_input = gr.Textbox(label="Enter your prompt")
47
+ seed_input = gr.Textbox(label="Enter seed", type="password")
48
+ generate_button = gr.Button("Generate Image")
49
+
50
+ file_explorer = gr.FileExplorer(
51
+ glob="**/*.webp",
52
+ file_count="single",
53
+ root_dir=ROOT_DIR,
54
+ label="Select a WebP image",
55
+ visible=False
56
+ )
57
+ output_info = gr.Textbox(label="Output Information", lines=3)
58
+
59
+ with gr.Column(scale=2):
60
+ shared_image = gr.Image(label="Image Display")
61
+
62
+ # Set up event handlers
63
+ generate_button.click(
64
+ generate_image,
65
+ inputs=prompt_input,
66
+ outputs=[shared_image, output_info]
67
  )
 
 
68
 
69
+ seed_input.change(
70
+ check_seed,
71
+ inputs=seed_input,
72
+ outputs=file_explorer
73
+ )
74
+
75
+ file_explorer.change(
76
+ show_image,
77
+ inputs=file_explorer,
78
+ outputs=[shared_image, output_info]
79
+ )
80
 
81
  logger.info("Launching Gradio app")
82