ivorobyev commited on
Commit
b3119be
·
verified ·
1 Parent(s): 50bf798

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +59 -1
app.py CHANGED
@@ -114,8 +114,66 @@ with gr.Blocks() as demo:
114
 
115
  gr.Examples(examples=examples, inputs=[h_text, l_text], label="Example sequences")
116
  btn = gr.Button("Predict Structure")
 
 
 
 
 
 
 
 
 
 
 
117
  output_html = gr.HTML()
118
- btn.click(pred_seq, inputs=[h_text, l_text], outputs=output_html)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
119
 
120
  if __name__ == "__main__":
121
  demo.launch(show_error=True, server_name="0.0.0.0")
 
114
 
115
  gr.Examples(examples=examples, inputs=[h_text, l_text], label="Example sequences")
116
  btn = gr.Button("Predict Structure")
117
+
118
+ progress_bar = gr.HTML("""
119
+ <div id="progress" style="display: none; margin: 20px 0;">
120
+ <div style="width: 100%; background: #f0f0f0; border-radius: 5px;">
121
+ <div id="progress-bar" style="height: 20px; width: 0%; background: linear-gradient(90deg, #4CAF50 0%, #8BC34A 100%); border-radius: 5px; transition: width 0.5s;">
122
+ <div style="text-align: center; color: white; line-height: 20px;">Processing...</div>
123
+ </div>
124
+ </div>
125
+ </div>
126
+ """)
127
+
128
  output_html = gr.HTML()
129
+
130
+ js_animation = """
131
+ <script>
132
+ function startProgress() {
133
+ const progress = document.getElementById("progress");
134
+ const progressBar = document.getElementById("progress-bar");
135
+ progress.style.display = "block";
136
+
137
+ let width = 0;
138
+ const interval = setInterval(() => {
139
+ if (width >= 90) {
140
+ clearInterval(interval);
141
+ return;
142
+ }
143
+ width += 5;
144
+ progressBar.style.width = width + "%";
145
+ }, 500);
146
+
147
+ return interval;
148
+ }
149
+ </script>
150
+ """
151
+
152
+ gr.HTML(js_animation)
153
+
154
+ def wrapper_pred_seq(h_seq, l_seq):
155
+ import time
156
+ progress_js = """
157
+ <script>
158
+ const interval = startProgress();
159
+ </script>
160
+ """
161
+
162
+ result = pred_seq(h_seq, l_seq)
163
+
164
+ complete_js = """
165
+ <script>
166
+ if (typeof interval !== 'undefined') clearInterval(interval);
167
+ document.getElementById("progress-bar").style.width = "100%";
168
+ setTimeout(() => {
169
+ document.getElementById("progress").style.display = "none";
170
+ }, 1000);
171
+ </script>
172
+ """
173
+
174
+ return progress_js + result + complete_js
175
+
176
+ btn.click(wrapper_pred_seq, inputs=[h_text, l_text], outputs=output_html)
177
 
178
  if __name__ == "__main__":
179
  demo.launch(show_error=True, server_name="0.0.0.0")