Spaces:
Sleeping
Sleeping
Minor bug fixes
Browse files- app/db.py +1 -8
- app/fn.py +2 -2
- app/main.py +9 -4
- utils/ui.py +0 -65
app/db.py
CHANGED
@@ -6,10 +6,9 @@ from time import time
|
|
6 |
|
7 |
import gradio as gr
|
8 |
import pytz
|
9 |
-
import requests
|
10 |
from tinydb import TinyDB, where
|
11 |
|
12 |
-
from app.fn import send_email
|
13 |
|
14 |
SERVER_DATA_DIR = os.getenv('DATA', 'results')
|
15 |
DB_EXPIRY = timedelta(hours=48).total_seconds()
|
@@ -33,12 +32,6 @@ def ts_to_str(timestamp, timezone):
|
|
33 |
# Format the datetime object to the specified string format
|
34 |
return localized_dt.strftime('%Y-%m-%d %H:%M:%S (%Z%z)')
|
35 |
|
36 |
-
def get_timezone_by_ip(ip):
|
37 |
-
try:
|
38 |
-
data = requests.get(f'https://worldtimeapi.org/api/ip/{ip}').json()
|
39 |
-
return data['timezone']
|
40 |
-
except Exception:
|
41 |
-
return 'UTC'
|
42 |
|
43 |
class JobDB(TinyDB):
|
44 |
def remove_job_record(self,job_id):
|
|
|
6 |
|
7 |
import gradio as gr
|
8 |
import pytz
|
|
|
9 |
from tinydb import TinyDB, where
|
10 |
|
11 |
+
from app.fn import send_email, get_timezone_by_ip
|
12 |
|
13 |
SERVER_DATA_DIR = os.getenv('DATA', 'results')
|
14 |
DB_EXPIRY = timedelta(hours=48).total_seconds()
|
|
|
32 |
# Format the datetime object to the specified string format
|
33 |
return localized_dt.strftime('%Y-%m-%d %H:%M:%S (%Z%z)')
|
34 |
|
|
|
|
|
|
|
|
|
|
|
|
|
35 |
|
36 |
class JobDB(TinyDB):
|
37 |
def remove_job_record(self,job_id):
|
app/fn.py
CHANGED
@@ -182,9 +182,9 @@ FILTER_MAP = {
|
|
182 |
}
|
183 |
|
184 |
|
185 |
-
def get_timezone_by_ip(ip
|
186 |
try:
|
187 |
-
data =
|
188 |
return data['timezone']
|
189 |
except Exception:
|
190 |
return 'UTC'
|
|
|
182 |
}
|
183 |
|
184 |
|
185 |
+
def get_timezone_by_ip(ip):
|
186 |
try:
|
187 |
+
data = requests.get(f'https://worldtimeapi.org/api/ip/{ip}').json()
|
188 |
return data['timezone']
|
189 |
except Exception:
|
190 |
return 'UTC'
|
app/main.py
CHANGED
@@ -1,4 +1,7 @@
|
|
|
|
|
|
1 |
import os
|
|
|
2 |
import uuid
|
3 |
import zipfile
|
4 |
from datetime import datetime
|
@@ -21,7 +24,8 @@ from inference import (read_fragment_library, process_fragment_library, extract_
|
|
21 |
from app import static, fn, db
|
22 |
|
23 |
|
24 |
-
|
|
|
25 |
job_db = db.init_job_db()
|
26 |
os.chmod('./fpocket', 0o755)
|
27 |
|
@@ -192,6 +196,7 @@ def job_validate(
|
|
192 |
|
193 |
return job_info
|
194 |
|
|
|
195 |
def dock_link(
|
196 |
frag_lib, prot,
|
197 |
dock_n_steps, dock_n_poses, dock_confidence_threshold,
|
@@ -233,7 +238,7 @@ def dock_link(
|
|
233 |
temp_sigma_data_tr=config.temp_sigma_data_tr,
|
234 |
temp_sigma_data_rot=config.temp_sigma_data_rot,
|
235 |
temp_sigma_data_tor=config.temp_sigma_data_tor,
|
236 |
-
save_docking=
|
237 |
device=device,
|
238 |
)
|
239 |
|
@@ -650,7 +655,7 @@ with gr.Blocks(theme=THEME, title='GenFBDD', css=static.CSS, delete_cache=(3600,
|
|
650 |
raise ValueError(f"Unsupported method: {method}")
|
651 |
return {input_prot_file: gr.File(str(file), visible=True)}
|
652 |
except Exception as e:
|
653 |
-
gr.Error(f"Query error: {str(e)}")
|
654 |
|
655 |
prot_query_btn.click(
|
656 |
fn=pdb_query,
|
@@ -658,7 +663,7 @@ with gr.Blocks(theme=THEME, title='GenFBDD', css=static.CSS, delete_cache=(3600,
|
|
658 |
outputs=[input_prot_file],
|
659 |
)
|
660 |
|
661 |
-
|
662 |
fn=lambda: gr.Info('Rendering 3DMol view...'),
|
663 |
).then(
|
664 |
fn=lambda x, y: gr.Info('3DMol view rendered.'),
|
|
|
1 |
+
import spaces
|
2 |
+
|
3 |
import os
|
4 |
+
import tempfile
|
5 |
import uuid
|
6 |
import zipfile
|
7 |
from datetime import datetime
|
|
|
24 |
from app import static, fn, db
|
25 |
|
26 |
|
27 |
+
Path(tempfile.gettempdir(), 'gradio').mkdir(exist_ok=True)
|
28 |
+
gr.set_static_paths(paths=["data/", "results/", "app/"])
|
29 |
job_db = db.init_job_db()
|
30 |
os.chmod('./fpocket', 0o755)
|
31 |
|
|
|
196 |
|
197 |
return job_info
|
198 |
|
199 |
+
@spaces.GPU(duration=600)
|
200 |
def dock_link(
|
201 |
frag_lib, prot,
|
202 |
dock_n_steps, dock_n_poses, dock_confidence_threshold,
|
|
|
238 |
temp_sigma_data_tr=config.temp_sigma_data_tr,
|
239 |
temp_sigma_data_rot=config.temp_sigma_data_rot,
|
240 |
temp_sigma_data_tor=config.temp_sigma_data_tor,
|
241 |
+
save_docking=True,
|
242 |
device=device,
|
243 |
)
|
244 |
|
|
|
655 |
raise ValueError(f"Unsupported method: {method}")
|
656 |
return {input_prot_file: gr.File(str(file), visible=True)}
|
657 |
except Exception as e:
|
658 |
+
raise gr.Error(f"Query error: {str(e)}")
|
659 |
|
660 |
prot_query_btn.click(
|
661 |
fn=pdb_query,
|
|
|
663 |
outputs=[input_prot_file],
|
664 |
)
|
665 |
|
666 |
+
input_prot_file.change(
|
667 |
fn=lambda: gr.Info('Rendering 3DMol view...'),
|
668 |
).then(
|
669 |
fn=lambda x, y: gr.Info('3DMol view rendered.'),
|
utils/ui.py
DELETED
@@ -1,65 +0,0 @@
|
|
1 |
-
import os
|
2 |
-
import smtplib
|
3 |
-
from datetime import datetime
|
4 |
-
from email.mime.multipart import MIMEMultipart
|
5 |
-
from email.mime.text import MIMEText
|
6 |
-
from email.utils import formatdate, make_msgid
|
7 |
-
|
8 |
-
import pytz
|
9 |
-
from markdown import markdown
|
10 |
-
|
11 |
-
|
12 |
-
def get_timezone_by_ip(ip, session):
|
13 |
-
try:
|
14 |
-
data = session.get(f'https://worldtimeapi.org/api/ip/{ip}').json()
|
15 |
-
return data['timezone']
|
16 |
-
except Exception:
|
17 |
-
return 'UTC'
|
18 |
-
|
19 |
-
|
20 |
-
def ts_to_str(timestamp, timezone):
|
21 |
-
# Create a timezone-aware datetime object from the UNIX timestamp
|
22 |
-
dt = datetime.fromtimestamp(timestamp, pytz.utc)
|
23 |
-
|
24 |
-
# Convert the timezone-aware datetime object to the target timezone
|
25 |
-
target_timezone = pytz.timezone(timezone)
|
26 |
-
localized_dt = dt.astimezone(target_timezone)
|
27 |
-
|
28 |
-
# Format the datetime object to the specified string format
|
29 |
-
return localized_dt.strftime('%Y-%m-%d %H:%M:%S (%Z%z)')
|
30 |
-
|
31 |
-
|
32 |
-
def send_email(job_info):
|
33 |
-
if job_info.get('email'):
|
34 |
-
try:
|
35 |
-
email_info = job_info.copy()
|
36 |
-
email_serv = os.getenv('EMAIL_SERV')
|
37 |
-
email_port = os.getenv('EMAIL_PORT')
|
38 |
-
email_addr = os.getenv('EMAIL_ADDR')
|
39 |
-
email_pass = os.getenv('EMAIL_PASS')
|
40 |
-
email_form = os.getenv('EMAIL_FORM')
|
41 |
-
email_subj = os.getenv('EMAIL_SUBJ')
|
42 |
-
|
43 |
-
for key, value in email_info.items():
|
44 |
-
if key.endswith("time") and value:
|
45 |
-
email_info[key] = ts_to_str(value, get_timezone_by_ip(email_info['ip']))
|
46 |
-
|
47 |
-
server = smtplib.SMTP(email_serv, int(email_port))
|
48 |
-
# server.starttls()
|
49 |
-
|
50 |
-
server.login(email_addr, email_pass)
|
51 |
-
msg = MIMEMultipart("alternative")
|
52 |
-
msg["From"] = email_addr
|
53 |
-
msg["To"] = email_info['email']
|
54 |
-
msg["Subject"] = email_subj.format(**email_info)
|
55 |
-
msg["Date"] = formatdate(localtime=True)
|
56 |
-
msg["Message-ID"] = make_msgid()
|
57 |
-
|
58 |
-
msg.attach(MIMEText(markdown(email_form.format(**email_info)), 'html'))
|
59 |
-
msg.attach(MIMEText(email_form.format(**email_info), 'plain'))
|
60 |
-
|
61 |
-
server.sendmail(email_addr, email_info['email'], msg.as_string())
|
62 |
-
server.quit()
|
63 |
-
gr.Info('Email notification sent.')
|
64 |
-
except Exception as e:
|
65 |
-
gr.Warning('Failed to send email notification due to error: ' + str(e))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|