libokj commited on
Commit
6f7cde8
·
1 Parent(s): 642d891

Minor bug fixes

Browse files
Files changed (2) hide show
  1. app/main.py +33 -35
  2. app/static.py +1 -1
app/main.py CHANGED
@@ -1,4 +1,3 @@
1
- import asyncio
2
  import queue
3
  import threading
4
 
@@ -11,7 +10,7 @@ import uuid
11
  import zipfile
12
  from datetime import datetime
13
  from pathlib import Path
14
- from time import time
15
 
16
  from dotenv import load_dotenv
17
  import torch
@@ -94,18 +93,17 @@ def gr_error_wrapper(func):
94
  return wrapper
95
 
96
 
97
- async def query_job_status(job_id):
98
  stop = False
99
- interval = 3 # Check every 3 seconds for better responsiveness
100
  retry = 0
101
-
102
  while not stop:
103
- # Wait for a short interval before checking again
104
- await asyncio.sleep(interval) # Non-blocking sleep
105
  job = job_db.job_lookup(job_id)
106
 
107
  if job: # If the job exists
108
- if job['status'] == "RUNNING": # If the job is still running
109
  yield {
110
  pred_lookup_status: f'''
111
  Your job (ID: **{job['id']}**) started at **{job['start_time']}** and is **RUNNING...**
@@ -114,35 +112,36 @@ async def query_job_status(job_id):
114
  You may keep the page open or close it and revisit later using the job ID.
115
  You will receive an email notification once the job is done.
116
  ''',
117
- pred_lookup_btn: gr.update(visible=False),
118
- pred_lookup_stop_btn: gr.update(visible=True),
 
119
  }
120
 
121
- elif job['status'] == "COMPLETED": # If the job is complete
122
  stop = True
123
  msg = f"Your job (ID: {job['id']}) has been **COMPLETED**"
124
  msg += f" at **{job['end_time']}**" if job.get('end_time') else ""
125
  msg += f" and the results will **EXPIRE** by **{job['expiry_time']}**." if job.get('expiry_time') else "."
126
  msg += " Redirecting to the results page..."
127
-
128
  yield {
129
  pred_lookup_status: msg,
130
  tabs: gr.Tabs(selected='result'),
131
  result_state: job,
132
- pred_lookup_btn: gr.update(visible=True),
133
- pred_lookup_stop_btn: gr.update(visible=False),
 
134
  }
135
 
136
- elif job['status'] == "FAILED": # If the job failed
137
  stop = True
138
  msg = f'Your job (ID: {job_id}) has **FAILED**'
139
  msg += f" at {job['end_time']}" if job.get('end_time') else ''
140
  msg += f" due to error: {job['error']}." if job.get('error') else '.'
141
-
142
  yield {
143
  pred_lookup_status: msg,
144
- pred_lookup_btn: gr.update(visible=True),
145
- pred_lookup_stop_btn: gr.update(visible=False),
 
146
  }
147
 
148
  else: # If the job is not found
@@ -155,11 +154,11 @@ async def query_job_status(job_id):
155
  retry += 1
156
  yield {
157
  pred_lookup_status: msg,
158
- pred_lookup_btn: gr.update(visible=stop),
159
- pred_lookup_stop_btn: gr.update(visible=not stop),
 
160
  }
161
 
162
-
163
  def checkbox_group_selections_to_kwargs(selected_options, option_mapping):
164
  kwargs = {
165
  option_mapping[label]: label in selected_options
@@ -555,6 +554,7 @@ with gr.Blocks(theme=THEME, title='GenFBDD', css=static.CSS, delete_cache=(3600,
555
  label='Input Your Job ID', placeholder='e.g., e9dfd149-3f5c-48a6-b797-c27d027611ac',
556
  info="Your job ID is a UUID4 string that you receive after submitting a job on the "
557
  "page or in the email notification.")
 
558
  pred_lookup_btn = gr.Button(value='Query Status', variant='primary', visible=True)
559
  pred_lookup_stop_btn = gr.Button(value='Stop Tracking', variant='stop', visible=False)
560
  pred_lookup_status = gr.Markdown("**Job Status**", container=True)
@@ -569,7 +569,6 @@ with gr.Blocks(theme=THEME, title='GenFBDD', css=static.CSS, delete_cache=(3600,
569
  with gr.Row():
570
  scores = gr.CheckboxGroup(list(fn.SCORE_MAP.keys()), label='Compound Scores')
571
  filters = gr.CheckboxGroup(list(fn.FILTER_MAP.keys()), label='Compound Filters')
572
- result_example = gr.Button('Example', elem_classes=['example'])
573
  with gr.Row():
574
  prop_clr_btn = gr.ClearButton(value='Clear Properties', interactive=False)
575
  prop_calc_btn = gr.Button(value='Calculate Properties', interactive=False, variant='primary')
@@ -775,10 +774,10 @@ with gr.Blocks(theme=THEME, title='GenFBDD', css=static.CSS, delete_cache=(3600,
775
  gr.update(visible=True),
776
  ],
777
  outputs=[pred_lookup_status, pred_lookup_btn, pred_lookup_stop_btn],
778
- ).success(
779
  fn=query_job_status,
780
  inputs=[pred_lookup_id],
781
- outputs=[pred_lookup_status, tabs, result_state, pred_lookup_btn, pred_lookup_stop_btn],
782
  show_progress='minimal',
783
  )
784
 
@@ -789,32 +788,32 @@ with gr.Blocks(theme=THEME, title='GenFBDD', css=static.CSS, delete_cache=(3600,
789
  gr.update(visible=True),
790
  ],
791
  outputs=[pred_lookup_status, pred_lookup_btn, pred_lookup_stop_btn],
792
- ).success(
793
  fn=query_job_status,
794
  inputs=pred_lookup_id,
795
- outputs=[pred_lookup_status, tabs, result_state, pred_lookup_btn, pred_lookup_stop_btn],
796
  show_progress='minimal',
797
  cancels=[user_job_lookup],
798
  )
799
 
800
- pred_lookup_stop_btn.click(
801
- fn=lambda: [gr.Button(visible=True), gr.Button(visible=False)],
802
- outputs=[pred_lookup_btn, pred_lookup_stop_btn],
803
- cancels=[user_job_lookup, auto_job_lookup],
804
- )
805
-
806
  result_example.click(
807
  fn=lambda: '80cf2658-7a1c-48d6-8372-61b978177fe6',
808
  outputs=[pred_lookup_id],
809
  show_progress='hidden'
810
- ).success(
811
  fn=query_job_status,
812
  inputs=pred_lookup_id,
813
- outputs=[pred_lookup_status, tabs, result_state, pred_lookup_btn, pred_lookup_stop_btn],
814
  show_progress='minimal',
815
  cancels=[user_job_lookup, auto_job_lookup],
816
  )
817
 
 
 
 
 
 
 
818
  ### Results
819
  def update_results(result_info):
820
  result_dir = Path(result_info['output_dir'])
@@ -927,5 +926,4 @@ demo.launch(
927
  max_file_size="5mb",
928
  ssr_mode=False,
929
  show_api=False,
930
- enable_monitoring=True,
931
  )
 
 
1
  import queue
2
  import threading
3
 
 
10
  import zipfile
11
  from datetime import datetime
12
  from pathlib import Path
13
+ from time import time, sleep
14
 
15
  from dotenv import load_dotenv
16
  import torch
 
93
  return wrapper
94
 
95
 
96
+ def query_job_status(job_id):
97
  stop = False
98
+ interval = 3
99
  retry = 0
100
+ gr.Info('Start querying job status...')
101
  while not stop:
102
+ sleep(interval)
 
103
  job = job_db.job_lookup(job_id)
104
 
105
  if job: # If the job exists
106
+ if job['status'] == "RUNNING":
107
  yield {
108
  pred_lookup_status: f'''
109
  Your job (ID: **{job['id']}**) started at **{job['start_time']}** and is **RUNNING...**
 
112
  You may keep the page open or close it and revisit later using the job ID.
113
  You will receive an email notification once the job is done.
114
  ''',
115
+ pred_lookup_btn: gr.Button(visible=False),
116
+ pred_lookup_stop_btn: gr.Button(visible=True),
117
+ result_example: gr.Button(visible=False),
118
  }
119
 
120
+ elif job['status'] == "COMPLETED":
121
  stop = True
122
  msg = f"Your job (ID: {job['id']}) has been **COMPLETED**"
123
  msg += f" at **{job['end_time']}**" if job.get('end_time') else ""
124
  msg += f" and the results will **EXPIRE** by **{job['expiry_time']}**." if job.get('expiry_time') else "."
125
  msg += " Redirecting to the results page..."
 
126
  yield {
127
  pred_lookup_status: msg,
128
  tabs: gr.Tabs(selected='result'),
129
  result_state: job,
130
+ pred_lookup_btn: gr.Button(visible=True),
131
+ pred_lookup_stop_btn: gr.Button(visible=False),
132
+ result_example: gr.Button(visible=True),
133
  }
134
 
135
+ elif job['status'] == "FAILED":
136
  stop = True
137
  msg = f'Your job (ID: {job_id}) has **FAILED**'
138
  msg += f" at {job['end_time']}" if job.get('end_time') else ''
139
  msg += f" due to error: {job['error']}." if job.get('error') else '.'
 
140
  yield {
141
  pred_lookup_status: msg,
142
+ pred_lookup_btn: gr.Button(visible=True),
143
+ pred_lookup_stop_btn: gr.Button(visible=False),
144
+ result_example: gr.Button(visible=True),
145
  }
146
 
147
  else: # If the job is not found
 
154
  retry += 1
155
  yield {
156
  pred_lookup_status: msg,
157
+ pred_lookup_btn: gr.Button(visible=stop),
158
+ pred_lookup_stop_btn: gr.Button(visible=not stop),
159
+ result_example: gr.Button(visible=stop),
160
  }
161
 
 
162
  def checkbox_group_selections_to_kwargs(selected_options, option_mapping):
163
  kwargs = {
164
  option_mapping[label]: label in selected_options
 
554
  label='Input Your Job ID', placeholder='e.g., e9dfd149-3f5c-48a6-b797-c27d027611ac',
555
  info="Your job ID is a UUID4 string that you receive after submitting a job on the "
556
  "page or in the email notification.")
557
+ result_example = gr.Button('Example', elem_classes=['example'])
558
  pred_lookup_btn = gr.Button(value='Query Status', variant='primary', visible=True)
559
  pred_lookup_stop_btn = gr.Button(value='Stop Tracking', variant='stop', visible=False)
560
  pred_lookup_status = gr.Markdown("**Job Status**", container=True)
 
569
  with gr.Row():
570
  scores = gr.CheckboxGroup(list(fn.SCORE_MAP.keys()), label='Compound Scores')
571
  filters = gr.CheckboxGroup(list(fn.FILTER_MAP.keys()), label='Compound Filters')
 
572
  with gr.Row():
573
  prop_clr_btn = gr.ClearButton(value='Clear Properties', interactive=False)
574
  prop_calc_btn = gr.Button(value='Calculate Properties', interactive=False, variant='primary')
 
774
  gr.update(visible=True),
775
  ],
776
  outputs=[pred_lookup_status, pred_lookup_btn, pred_lookup_stop_btn],
777
+ ).then(
778
  fn=query_job_status,
779
  inputs=[pred_lookup_id],
780
+ outputs=[pred_lookup_status, tabs, result_state, pred_lookup_btn, pred_lookup_stop_btn, result_example],
781
  show_progress='minimal',
782
  )
783
 
 
788
  gr.update(visible=True),
789
  ],
790
  outputs=[pred_lookup_status, pred_lookup_btn, pred_lookup_stop_btn],
791
+ ).then(
792
  fn=query_job_status,
793
  inputs=pred_lookup_id,
794
+ outputs=[pred_lookup_status, tabs, result_state, pred_lookup_btn, pred_lookup_stop_btn, result_example],
795
  show_progress='minimal',
796
  cancels=[user_job_lookup],
797
  )
798
 
 
 
 
 
 
 
799
  result_example.click(
800
  fn=lambda: '80cf2658-7a1c-48d6-8372-61b978177fe6',
801
  outputs=[pred_lookup_id],
802
  show_progress='hidden'
803
+ ).then(
804
  fn=query_job_status,
805
  inputs=pred_lookup_id,
806
+ outputs=[pred_lookup_status, tabs, result_state, pred_lookup_btn, pred_lookup_stop_btn, result_example],
807
  show_progress='minimal',
808
  cancels=[user_job_lookup, auto_job_lookup],
809
  )
810
 
811
+ pred_lookup_stop_btn.click(
812
+ fn=lambda: [gr.Button(visible=True), gr.Button(visible=False), gr.Button(visible=True)],
813
+ outputs=[pred_lookup_btn, pred_lookup_stop_btn, result_example],
814
+ cancels=[user_job_lookup, auto_job_lookup],
815
+ )
816
+
817
  ### Results
818
  def update_results(result_info):
819
  result_dir = Path(result_info['output_dir'])
 
926
  max_file_size="5mb",
927
  ssr_mode=False,
928
  show_api=False,
 
929
  )
app/static.py CHANGED
@@ -136,7 +136,7 @@ CSS = """
136
  text-decoration: underline;
137
  box-shadow: none;
138
  text-align: left !important;
139
- display: inline-block !important;
140
  }
141
 
142
  footer {
 
136
  text-decoration: underline;
137
  box-shadow: none;
138
  text-align: left !important;
139
+ display: block;
140
  }
141
 
142
  footer {