saq1b commited on
Commit
e6b9488
·
verified ·
1 Parent(s): 3566679

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -19
app.py CHANGED
@@ -132,7 +132,34 @@ def undo_edit(image_history):
132
 
133
  # Create Gradio UI
134
  def create_ui():
135
- with gr.Blocks(title="Gemini Image Editor") as app:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
136
  gr.Markdown("# Gemini Image Editor")
137
  gr.Markdown("Upload an image, enter a description of the edit you want, and let Gemini do the rest!")
138
 
@@ -166,24 +193,6 @@ def create_ui():
166
  inputs=[image_history],
167
  outputs=[output_image, image_history, status]
168
  )
169
-
170
- # JavaScript for saving API key in local storage
171
- app.load(None, None, None, _js="""
172
- function() {
173
- // Try to load saved API key from localStorage
174
- const savedKey = localStorage.getItem('gemini_api_key');
175
- if (savedKey) {
176
- document.querySelector('input[data-testid="textbox"]#api_key').value = savedKey;
177
- }
178
-
179
- // Add event listener to save API key
180
- document.querySelector('input[data-testid="textbox"]#api_key').addEventListener('change', function(e) {
181
- if (document.querySelector('input[data-testid="checkbox"]#save_key').checked) {
182
- localStorage.setItem('gemini_api_key', e.target.value);
183
- }
184
- });
185
- }
186
- """)
187
 
188
  return app
189
 
 
132
 
133
  # Create Gradio UI
134
  def create_ui():
135
+ with gr.Blocks(title="Gemini Image Editor", js="""
136
+ function() {
137
+ // Wait for the DOM to be fully loaded
138
+ window.addEventListener('DOMContentLoaded', (event) => {
139
+ setTimeout(function() {
140
+ // Try to load saved API key from localStorage
141
+ const savedKey = localStorage.getItem('gemini_api_key');
142
+ const apiKeyInput = document.querySelector('input[placeholder="Enter your Gemini API key"]');
143
+ if (savedKey && apiKeyInput) {
144
+ apiKeyInput.value = savedKey;
145
+ // Dispatch an input event to make sure Gradio recognizes the change
146
+ const event = new Event('input', { bubbles: true });
147
+ apiKeyInput.dispatchEvent(event);
148
+ }
149
+
150
+ // Add event listener to save API key when checkbox is checked
151
+ const saveKeyCheckbox = document.querySelector('input[type="checkbox"]');
152
+ if (apiKeyInput && saveKeyCheckbox) {
153
+ apiKeyInput.addEventListener('change', function(e) {
154
+ if (saveKeyCheckbox.checked) {
155
+ localStorage.setItem('gemini_api_key', e.target.value);
156
+ }
157
+ });
158
+ }
159
+ }, 1000); // Small delay to ensure elements are loaded
160
+ });
161
+ }
162
+ """) as app:
163
  gr.Markdown("# Gemini Image Editor")
164
  gr.Markdown("Upload an image, enter a description of the edit you want, and let Gemini do the rest!")
165
 
 
193
  inputs=[image_history],
194
  outputs=[output_image, image_history, status]
195
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
196
 
197
  return app
198