gaur3009 commited on
Commit
78b6f06
·
verified ·
1 Parent(s): 5843ed7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -7
app.py CHANGED
@@ -45,8 +45,9 @@ def infer(color_prompt, phone_type_prompt, design_prompt):
45
 
46
  # Save the design
47
  def save_design(image):
48
- file_path = "saved_designs/saved_design.png"
49
- os.makedirs(os.path.dirname(file_path), exist_ok=True)
 
50
  image.save(file_path)
51
  return f"Design saved as {file_path}!"
52
 
@@ -119,13 +120,21 @@ with gr.Blocks(css=custom_css) as interface:
119
  with gr.Tabs():
120
  with gr.Tab("Home"):
121
  gr.Markdown("Welcome to the **AI Phone Cover Designer**! Below are some of your saved designs.")
122
- saved_images_gallery = gr.Gallery(label="Saved Designs")
123
 
124
- # Load the saved designs dynamically when the tab is rendered
125
- def display_saved_designs():
 
 
 
 
 
126
  return fetch_saved_designs()
127
 
128
- saved_images_gallery.render(value=fetch_saved_designs())
 
 
 
 
129
 
130
  with gr.Tab("Design"):
131
  with gr.Row():
@@ -167,4 +176,4 @@ with gr.Blocks(css=custom_css) as interface:
167
  """)
168
 
169
  # Launch the app
170
- interface.launch(debug=True)
 
45
 
46
  # Save the design
47
  def save_design(image):
48
+ saved_designs_dir = "saved_designs"
49
+ os.makedirs(saved_designs_dir, exist_ok=True)
50
+ file_path = os.path.join(saved_designs_dir, f"design_{int(time.time())}.png")
51
  image.save(file_path)
52
  return f"Design saved as {file_path}!"
53
 
 
120
  with gr.Tabs():
121
  with gr.Tab("Home"):
122
  gr.Markdown("Welcome to the **AI Phone Cover Designer**! Below are some of your saved designs.")
 
123
 
124
+ # Gallery to display saved designs
125
+ saved_images_gallery = gr.Gallery(label="Saved Designs").style(grid=[2], height="400px")
126
+
127
+ # Button to refresh gallery
128
+ refresh_button = gr.Button("Refresh Gallery")
129
+
130
+ def refresh_gallery():
131
  return fetch_saved_designs()
132
 
133
+ refresh_button.click(
134
+ refresh_gallery,
135
+ inputs=[],
136
+ outputs=[saved_images_gallery]
137
+ )
138
 
139
  with gr.Tab("Design"):
140
  with gr.Row():
 
176
  """)
177
 
178
  # Launch the app
179
+ interface.launch(debug=True)