prithivMLmods commited on
Commit
7fd2422
·
verified ·
1 Parent(s): 4965c35

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -45
app.py CHANGED
@@ -9,7 +9,8 @@ import spaces
9
  import torch
10
  from diffusers import StableDiffusionXLPipeline, EulerAncestralDiscreteScheduler
11
 
12
- DESCRIPTIONx = """## STABLE HAMSTER"""
 
13
 
14
  # Use environment variables for flexibility
15
  MODEL_ID = os.getenv("MODEL_REPO")
@@ -111,50 +112,7 @@ footer {
111
  }
112
  '''
113
 
114
- # Define the content of index.html with a loading animation and delay
115
- index_html_content = """
116
- <!DOCTYPE html>
117
- <html lang="en">
118
- <head>
119
- <meta charset="UTF-8">
120
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
121
- <title>Loading...</title>
122
- <style>
123
- /* Define your loading animation CSS here */
124
- .loading-animation {
125
- /* Example styles */
126
- width: 100px;
127
- height: 100px;
128
- background-color: #f0f0f0;
129
- border-radius: 50%;
130
- animation: spin 2s linear infinite;
131
- margin: 100px auto;
132
- }
133
- @keyframes spin {
134
- 0% { transform: rotate(0deg); }
135
- 100% { transform: rotate(360deg); }
136
- }
137
- </style>
138
- </head>
139
- <body>
140
- <div class="loading-animation"></div>
141
- <script>
142
- // Delay for 5-6 seconds before transitioning to Gradio UI
143
- setTimeout(function() {
144
- window.location.href = '/'; // Redirect to Gradio UI
145
- }, 5000); // Adjust time as needed (5000 = 5 seconds)
146
- </script>
147
- </body>
148
- </html>
149
- """
150
-
151
- # Save index.html to the current directory
152
- with open("assets/index.html", "w") as f:
153
- f.write(index_html_content)
154
-
155
- # Embed index.html into Gradio UI
156
  with gr.Blocks(css=css, theme="bethecloud/storj_theme") as demo:
157
- gr.HTML(index_html_content) # Embed the HTML content here
158
  gr.Markdown(DESCRIPTIONx)
159
  with gr.Group():
160
  with gr.Row():
@@ -167,6 +125,13 @@ with gr.Blocks(css=css, theme="bethecloud/storj_theme") as demo:
167
  )
168
  run_button = gr.Button("Run", scale=0)
169
  result = gr.Gallery(label="Result", columns=1, show_label=False)
 
 
 
 
 
 
 
170
  with gr.Accordion("Advanced options", open=False):
171
  num_images = gr.Slider(
172
  label="Number of Images",
@@ -237,10 +202,18 @@ with gr.Blocks(css=css, theme="bethecloud/storj_theme") as demo:
237
  api_name=False,
238
  )
239
 
 
 
 
 
 
 
 
 
 
240
  gr.on(
241
  triggers=[
242
  prompt.submit,
243
- negative_prompt.submit,
244
  run_button.click,
245
  ],
246
  fn=generate,
@@ -258,6 +231,7 @@ with gr.Blocks(css=css, theme="bethecloud/storj_theme") as demo:
258
  ],
259
  outputs=[result, seed],
260
  api_name="run",
 
261
  )
262
 
263
  if __name__ == "__main__":
 
9
  import torch
10
  from diffusers import StableDiffusionXLPipeline, EulerAncestralDiscreteScheduler
11
 
12
+ DESCRIPTIONx = """## STABLE HAMSTER
13
+ """
14
 
15
  # Use environment variables for flexibility
16
  MODEL_ID = os.getenv("MODEL_REPO")
 
112
  }
113
  '''
114
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
115
  with gr.Blocks(css=css, theme="bethecloud/storj_theme") as demo:
 
116
  gr.Markdown(DESCRIPTIONx)
117
  with gr.Group():
118
  with gr.Row():
 
125
  )
126
  run_button = gr.Button("Run", scale=0)
127
  result = gr.Gallery(label="Result", columns=1, show_label=False)
128
+ loading_animation = gr.HTML(
129
+ """
130
+ <div id="loading-animation" style="display:none;">
131
+ <iframe src="https://prithivmlmods-hamster-static.static.hf.space/index.html" width="100%" height="200" style="border:none;"></iframe>
132
+ </div>
133
+ """
134
+ )
135
  with gr.Accordion("Advanced options", open=False):
136
  num_images = gr.Slider(
137
  label="Number of Images",
 
202
  api_name=False,
203
  )
204
 
205
+ def start_loading():
206
+ return gr.update(visible=True), gr.update(visible=False)
207
+
208
+ def stop_loading():
209
+ return gr.update(visible=False), gr.update(visible=True)
210
+
211
+ prompt.submit(start_loading, [], [loading_animation, result], queue=False)
212
+ run_button.click(start_loading, [], [loading_animation, result], queue=False)
213
+
214
  gr.on(
215
  triggers=[
216
  prompt.submit,
 
217
  run_button.click,
218
  ],
219
  fn=generate,
 
231
  ],
232
  outputs=[result, seed],
233
  api_name="run",
234
+ postprocess_fn=stop_loading,
235
  )
236
 
237
  if __name__ == "__main__":