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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os,sys
|
2 |
+
import traceback # ์๋จ์ ์ถ๊ฐ
|
3 |
+
# install required packages
|
4 |
+
os.system('pip install plotly') # plotly ์ค์น
|
5 |
+
os.system('pip install matplotlib') # matplotlib ์ค์น
|
6 |
+
os.system('pip install dgl==1.0.2+cu116 -f https://data.dgl.ai/wheels/cu116/repo.html')
|
7 |
+
os.environ["DGLBACKEND"] = "pytorch"
|
8 |
+
print('Modules installed')
|
9 |
+
|
10 |
+
# ๊ธฐ๋ณธ args ์ค์
|
11 |
+
if not os.path.exists('./tmp'):
|
12 |
+
os.makedirs('./tmp')
|
13 |
+
|
14 |
+
if not os.path.exists('./tmp/args.json'):
|
15 |
+
default_args = {
|
16 |
+
'checkpoint': None,
|
17 |
+
'dump_trb': False,
|
18 |
+
'dump_args': True,
|
19 |
+
'save_best_plddt': True,
|
20 |
+
'T': 25,
|
21 |
+
'strand_bias': 0.0,
|
22 |
+
'loop_bias': 0.0,
|
23 |
+
'helix_bias': 0.0,
|
24 |
+
'd_t1d': 24,
|
25 |
+
'potentials': None,
|
26 |
+
'potential_scale': None,
|
27 |
+
'aa_composition': None
|
28 |
+
}
|
29 |
+
with open('./tmp/args.json', 'w') as f:
|
30 |
+
json.dump(default_args, f)
|
31 |
+
|
32 |
+
# ์ฒดํฌํฌ์ธํธ ํ์ผ ๋ค์ด๋ก๋
|
33 |
+
if not os.path.exists('./SEQDIFF_230205_dssp_hotspots_25mask_EQtasks_mod30.pt'):
|
34 |
+
print('Downloading model weights 1')
|
35 |
+
os.system('wget http://files.ipd.uw.edu/pub/sequence_diffusion/checkpoints/SEQDIFF_230205_dssp_hotspots_25mask_EQtasks_mod30.pt')
|
36 |
+
print('Successfully Downloaded')
|
37 |
+
|
38 |
+
if not os.path.exists('./SEQDIFF_221219_equalTASKS_nostrSELFCOND_mod30.pt'):
|
39 |
+
print('Downloading model weights 2')
|
40 |
+
os.system('wget http://files.ipd.uw.edu/pub/sequence_diffusion/checkpoints/SEQDIFF_221219_equalTASKS_nostrSELFCOND_mod30.pt')
|
41 |
+
print('Successfully Downloaded')
|
42 |
+
|
43 |
+
from openai import OpenAI
|
44 |
+
import gradio as gr
|
45 |
+
import json # json ๋ชจ๋ ์ถ๊ฐ
|
46 |
+
from datasets import load_dataset
|
47 |
+
import plotly.graph_objects as go
|
48 |
+
import numpy as np
|
49 |
+
import py3Dmol
|
50 |
+
from io import StringIO
|
51 |
+
import json
|
52 |
+
import secrets
|
53 |
+
import copy
|
54 |
+
import matplotlib.pyplot as plt
|
55 |
+
from utils.sampler import HuggingFace_sampler
|
56 |
+
from utils.parsers_inference import parse_pdb
|
57 |
+
from model.util import writepdb
|
58 |
+
from utils.inpainting_util import *
|
59 |
+
import os
|
60 |
+
|
61 |
+
# args ๋ก๋
|
62 |
+
with open('./tmp/args.json', 'r') as f:
|
63 |
+
args = json.load(f)
|
64 |
+
|
65 |
+
plt.rcParams.update({'font.size': 13})
|
66 |
+
|
67 |
+
# manually set checkpoint to load
|
68 |
+
args['checkpoint'] = None
|
69 |
+
args['dump_trb'] = False
|
70 |
+
args['dump_args'] = True
|
71 |
+
args['save_best_plddt'] = True
|
72 |
+
args['T'] = 25
|
73 |
+
args['strand_bias'] = 0.0
|
74 |
+
args['loop_bias'] = 0.0
|
75 |
+
args['helix_bias'] = 0.0
|
76 |
+
|
77 |
+
# Hugging Face ํ ํฐ ์ค์
|
78 |
+
ACCESS_TOKEN = os.getenv("HF_TOKEN")
|
79 |
+
if not ACCESS_TOKEN:
|
80 |
+
raise ValueError("HF_TOKEN not found in environment variables")
|
81 |
+
|
82 |
+
# OpenAI ํด๋ผ์ด์ธํธ ์ค์ (Hugging Face ์๋ํฌ์ธํธ ์ฌ์ฉ)
|
83 |
+
client = OpenAI(
|
84 |
+
base_url="https://api-inference.huggingface.co/v1/",
|
85 |
+
api_key=ACCESS_TOKEN,
|
86 |
+
)
|
87 |
+
|
88 |
+
|
89 |
+
# ๋ฐ์ดํฐ์
๋ก๋ ๋ฐ ๊ตฌ์กฐ ํ์ธ
|
90 |
+
try:
|
91 |
+
ds = load_dataset("lamm-mit/protein_secondary_structure_from_PDB",
|
92 |
+
token=ACCESS_TOKEN)
|
93 |
+
print("Dataset structure:", ds)
|
94 |
+
print("First entry example:", next(iter(ds['train'])))
|
95 |
+
except Exception as e:
|
96 |
+
print(f"Dataset loading error: {str(e)}")
|
97 |
+
raise
|
98 |
+
|
99 |
+
def respond(
|
100 |
+
message,
|
101 |
+
history,
|
102 |
+
system_message,
|
103 |
+
max_tokens,
|
104 |
+
temperature,
|
105 |
+
top_p,
|
106 |
+
):
|
107 |
+
messages = [{"role": "system", "content": system_message}]
|
108 |
+
|
109 |
+
for msg in history:
|
110 |
+
messages.append({"role": "user", "content": msg[0]})
|
111 |
+
if msg[1]:
|
112 |
+
messages.append({"role": "assistant", "content": msg[1]})
|
113 |
+
|
114 |
+
messages.append({"role": "user", "content": message})
|
115 |
+
|
116 |
+
try:
|
117 |
+
response = ""
|
118 |
+
for chunk in client.chat.completions.create(
|
119 |
+
model="CohereForAI/c4ai-command-r-plus-08-2024",
|
120 |
+
max_tokens=max_tokens,
|
121 |
+
stream=True,
|
122 |
+
temperature=temperature,
|
123 |
+
top_p=top_p,
|
124 |
+
messages=messages,
|
125 |
+
):
|
126 |
+
if hasattr(chunk.choices[0].delta, 'content'):
|
127 |
+
token = chunk.choices[0].delta.content
|
128 |
+
if token is not None:
|
129 |
+
response += token
|
130 |
+
yield [{"role": "user", "content": message},
|
131 |
+
{"role": "assistant", "content": response}]
|
132 |
+
|
133 |
+
return [{"role": "user", "content": message},
|
134 |
+
{"role": "assistant", "content": response}]
|
135 |
+
except Exception as e:
|
136 |
+
print(f"Error in respond: {str(e)}")
|
137 |
+
return [{"role": "user", "content": message},
|
138 |
+
{"role": "assistant", "content": f"์ค๋ฅ๊ฐ ๋ฐ์ํ์ต๋๋ค: {str(e)}"}]
|
139 |
+
|
140 |
+
def analyze_prompt(message):
|
141 |
+
"""LLM์ ์ฌ์ฉํ์ฌ ํ๋กฌํํธ ๋ถ์"""
|
142 |
+
try:
|
143 |
+
analysis_prompt = f"""
|
144 |
+
๋ค์ ์์ฒญ์ ๋ถ์ํ์ฌ ๋จ๋ฐฑ์ง ์ค๊ณ์ ํ์ํ ์ฃผ์ ํน์ฑ์ ์ถ์ถํ์ธ์:
|
145 |
+
์์ฒญ: {message}
|
146 |
+
|
147 |
+
๋ค์ ํญ๋ชฉ๋ค์ ๋ถ์ํด์ฃผ์ธ์:
|
148 |
+
1. ์ฃผ์ ๊ธฐ๋ฅ (์: ์น๋ฃ, ๊ฒฐํฉ, ์ด๋งค ๋ฑ)
|
149 |
+
2. ๋ชฉํ ํ๊ฒฝ (์: ์ธํฌ๋ง, ์์ฉ์ฑ, ๋ฑ)
|
150 |
+
3. ํ์ํ ๊ตฌ์กฐ์ ํน์ง
|
151 |
+
4. ํฌ๊ธฐ ๋ฐ ๋ณต์ก๋ ์๊ตฌ์ฌํญ
|
152 |
+
"""
|
153 |
+
|
154 |
+
response = client.chat.completions.create(
|
155 |
+
model="CohereForAI/c4ai-command-r-plus-08-2024",
|
156 |
+
messages=[{"role": "user", "content": analysis_prompt}],
|
157 |
+
temperature=0.7
|
158 |
+
)
|
159 |
+
|
160 |
+
return response.choices[0].message.content
|
161 |
+
except Exception as e:
|
162 |
+
print(f"ํ๋กฌํํธ ๋ถ์ ์ค ์ค๋ฅ: {str(e)}")
|
163 |
+
return None
|
164 |
+
|
165 |
+
def search_protein_data(analysis, dataset):
|
166 |
+
"""๋ถ์ ๊ฒฐ๊ณผ๋ฅผ ๋ฐํ์ผ๋ก ๋ฐ์ดํฐ์
์์ ์ ์ฌํ ๊ตฌ์กฐ ๊ฒ์"""
|
167 |
+
try:
|
168 |
+
# ํค์๋ ์ถ์ถ
|
169 |
+
keywords = extract_keywords(analysis)
|
170 |
+
print("Extracted keywords:", keywords)
|
171 |
+
|
172 |
+
# ๋ฐ์ดํฐ์
๊ตฌ์กฐ ํ์ธ
|
173 |
+
if not dataset or 'train' not in dataset:
|
174 |
+
print("Invalid dataset structure")
|
175 |
+
return []
|
176 |
+
|
177 |
+
# ์ ์ฌ๋ ์ ์ ๊ณ์ฐ
|
178 |
+
scored_entries = []
|
179 |
+
for entry in dataset['train']:
|
180 |
+
try:
|
181 |
+
score = calculate_similarity(keywords, entry)
|
182 |
+
scored_entries.append((score, entry))
|
183 |
+
except Exception as e:
|
184 |
+
print(f"Error processing entry: {str(e)}")
|
185 |
+
continue
|
186 |
+
|
187 |
+
# ๊ฒฐ๊ณผ ์ ๋ ฌ ๋ฐ ๋ฐํ
|
188 |
+
scored_entries.sort(reverse=True)
|
189 |
+
return scored_entries[:3]
|
190 |
+
|
191 |
+
except Exception as e:
|
192 |
+
print(f"๋ฐ์ดํฐ ๊ฒ์ ์ค ์ค๋ฅ: {str(e)}")
|
193 |
+
return []
|
194 |
+
|
195 |
+
def extract_parameters(analysis, similar_structures):
|
196 |
+
"""๋ถ์ ๊ฒฐ๊ณผ์ ์ ์ฌ ๊ตฌ์กฐ๋ฅผ ๋ฐํ์ผ๋ก ์์ฑ ํ๋ผ๋ฏธํฐ ๊ฒฐ์ """
|
197 |
+
try:
|
198 |
+
# ๊ธฐ๋ณธ ํ๋ผ๋ฏธํฐ ํ
ํ๋ฆฟ
|
199 |
+
params = {
|
200 |
+
'sequence_length': 100,
|
201 |
+
'helix_bias': 0.02,
|
202 |
+
'strand_bias': 0.02,
|
203 |
+
'loop_bias': 0.1,
|
204 |
+
'hydrophobic_target_score': 0
|
205 |
+
}
|
206 |
+
|
207 |
+
# ๋ถ์ ๊ฒฐ๊ณผ์์ ๊ตฌ์กฐ์ ์๊ตฌ์ฌํญ ํ์
|
208 |
+
if "๋ง ํฌ๊ณผ" in analysis or "์์์ฑ" in analysis:
|
209 |
+
params['hydrophobic_target_score'] = -2
|
210 |
+
params['helix_bias'] = 0.03
|
211 |
+
elif "์์ฉ์ฑ" in analysis or "๊ฐ์ฉ์ฑ" in analysis:
|
212 |
+
params['hydrophobic_target_score'] = 2
|
213 |
+
params['loop_bias'] = 0.15
|
214 |
+
|
215 |
+
# ์ ์ฌ ๊ตฌ์กฐ๋ค์ ํน์ฑ ๋ฐ์
|
216 |
+
if similar_structures:
|
217 |
+
avg_length = sum(len(s[1]['sequence']) for s in similar_structures) / len(similar_structures)
|
218 |
+
params['sequence_length'] = int(avg_length)
|
219 |
+
|
220 |
+
# ๊ตฌ์กฐ์ ํน์ฑ ๋ถ์ ๋ฐ ๋ฐ์
|
221 |
+
for _, structure in similar_structures:
|
222 |
+
if 'secondary_structure' in structure:
|
223 |
+
helix_ratio = structure['secondary_structure'].count('H') / len(structure['secondary_structure'])
|
224 |
+
sheet_ratio = structure['secondary_structure'].count('E') / len(structure['secondary_structure'])
|
225 |
+
params['helix_bias'] = max(0.01, min(0.05, helix_ratio))
|
226 |
+
params['strand_bias'] = max(0.01, min(0.05, sheet_ratio))
|
227 |
+
|
228 |
+
return params
|
229 |
+
except Exception as e:
|
230 |
+
print(f"ํ๋ผ๋ฏธํฐ ์ถ์ถ ์ค ์ค๋ฅ: {str(e)}")
|
231 |
+
return None
|
232 |
+
|
233 |
+
def process_chat(message, history):
|
234 |
+
try:
|
235 |
+
if any(keyword in message.lower() for keyword in ['protein', 'generate', '๋จ๋ฐฑ์ง', '์์ฑ', '์น๋ฃ']):
|
236 |
+
# 1. LLM์ ์ฌ์ฉํ ํ๋กฌํํธ ๋ถ์
|
237 |
+
analysis = analyze_prompt(message)
|
238 |
+
if not analysis:
|
239 |
+
return history + [
|
240 |
+
{"role": "user", "content": message},
|
241 |
+
{"role": "assistant", "content": "์์ฒญ ๋ถ์์ ์คํจํ์ต๋๋ค."}
|
242 |
+
]
|
243 |
+
|
244 |
+
# 2. ์ ์ฌ ๊ตฌ์กฐ ๊ฒ์
|
245 |
+
similar_structures = search_protein_data(analysis, ds)
|
246 |
+
if not similar_structures:
|
247 |
+
return history + [
|
248 |
+
{"role": "user", "content": message},
|
249 |
+
{"role": "assistant", "content": "์ ํฉํ ์ฐธ์กฐ ๊ตฌ์กฐ๋ฅผ ์ฐพ์ง ๋ชปํ์ต๋๋ค."}
|
250 |
+
]
|
251 |
+
|
252 |
+
# 3. ์์ฑ ํ๋ผ๋ฏธํฐ ๊ฒฐ์
|
253 |
+
params = extract_parameters(analysis, similar_structures)
|
254 |
+
if not params:
|
255 |
+
return history + [
|
256 |
+
{"role": "user", "content": message},
|
257 |
+
{"role": "assistant", "content": "ํ๋ผ๋ฏธํฐ ์ค์ ์ ์คํจํ์ต๋๋ค."}
|
258 |
+
]
|
259 |
+
|
260 |
+
# 4. ๋จ๋ฐฑ์ง ์์ฑ
|
261 |
+
try:
|
262 |
+
protein_result = protein_diffusion_model(
|
263 |
+
sequence=None,
|
264 |
+
seq_len=params['sequence_length'],
|
265 |
+
helix_bias=params['helix_bias'],
|
266 |
+
strand_bias=params['strand_bias'],
|
267 |
+
loop_bias=params['loop_bias'],
|
268 |
+
secondary_structure=None,
|
269 |
+
aa_bias=None,
|
270 |
+
aa_bias_potential=None,
|
271 |
+
num_steps="25",
|
272 |
+
noise="normal",
|
273 |
+
hydrophobic_target_score=str(params['hydrophobic_target_score']),
|
274 |
+
hydrophobic_potential="2",
|
275 |
+
contigs=None,
|
276 |
+
pssm=None,
|
277 |
+
seq_mask=None,
|
278 |
+
str_mask=None,
|
279 |
+
rewrite_pdb=None
|
280 |
+
)
|
281 |
+
|
282 |
+
output_seq, output_pdb, structure_view, plddt_plot = next(protein_result)
|
283 |
+
|
284 |
+
# 5. ๊ฒฐ๊ณผ ์ค๋ช
์์ฑ
|
285 |
+
explanation = f"""
|
286 |
+
์์ฒญํ์ ๊ธฐ๋ฅ์ ๋ง๋ ๋จ๋ฐฑ์ง์ ์์ฑํ์ต๋๋ค:
|
287 |
+
|
288 |
+
๋ถ์๋ ์๊ตฌ์ฌํญ:
|
289 |
+
{analysis}
|
290 |
+
|
291 |
+
์ค๊ณ๋ ๊ตฌ์กฐ์ ํน์ง:
|
292 |
+
- ๊ธธ์ด: {params['sequence_length']} ์๋ฏธ๋
ธ์ฐ
|
293 |
+
- ์ํ ํฌ๋ฆญ์ค ๋น์จ: {params['helix_bias']*100:.1f}%
|
294 |
+
- ๋ฒ ํ ์ํธ ๋น์จ: {params['strand_bias']*100:.1f}%
|
295 |
+
- ๋ฃจํ ๊ตฌ์กฐ ๋น์จ: {params['loop_bias']*100:.1f}%
|
296 |
+
- ์์์ฑ ์ ์: {params['hydrophobic_target_score']}
|
297 |
+
|
298 |
+
์ฐธ์กฐ๋ ์ ์ฌ ๊ตฌ์กฐ: {len(similar_structures)}๊ฐ
|
299 |
+
|
300 |
+
์์ฑ๋ ๋จ๋ฐฑ์ง์ 3D ๊ตฌ์กฐ์ ์ํ์ค๋ฅผ ํ์ธํ์ค ์ ์์ต๋๋ค.
|
301 |
+
"""
|
302 |
+
|
303 |
+
# 6. ๊ฒฐ๊ณผ ์ ์ฅ
|
304 |
+
global current_protein_result
|
305 |
+
current_protein_result = {
|
306 |
+
'sequence': output_seq,
|
307 |
+
'pdb': output_pdb,
|
308 |
+
'structure_view': structure_view,
|
309 |
+
'plddt_plot': plddt_plot,
|
310 |
+
'params': params
|
311 |
+
}
|
312 |
+
|
313 |
+
return history + [
|
314 |
+
{"role": "user", "content": message},
|
315 |
+
{"role": "assistant", "content": explanation}
|
316 |
+
]
|
317 |
+
|
318 |
+
except Exception as e:
|
319 |
+
return history + [
|
320 |
+
{"role": "user", "content": message},
|
321 |
+
{"role": "assistant", "content": f"๋จ๋ฐฑ์ง ์์ฑ ์ค ์ค๋ฅ๊ฐ ๋ฐ์ํ์ต๋๋ค: {str(e)}"}
|
322 |
+
]
|
323 |
+
else:
|
324 |
+
return history + [
|
325 |
+
{"role": "user", "content": message},
|
326 |
+
{"role": "assistant", "content": "๋จ๋ฐฑ์ง ์์ฑ ๊ด๋ จ ํค์๋๋ฅผ ํฌํจํด์ฃผ์ธ์."}
|
327 |
+
]
|
328 |
+
except Exception as e:
|
329 |
+
return history + [
|
330 |
+
{"role": "user", "content": message},
|
331 |
+
{"role": "assistant", "content": f"์ฒ๋ฆฌ ์ค ์ค๋ฅ๊ฐ ๋ฐ์ํ์ต๋๋ค: {str(e)}"}
|
332 |
+
]
|
333 |
+
|
334 |
+
|
335 |
+
def generate_protein(params):
|
336 |
+
# ๊ธฐ์กด protein_diffusion_model ํจ์ ํธ์ถ
|
337 |
+
result = protein_diffusion_model(
|
338 |
+
sequence=None,
|
339 |
+
seq_len=params['sequence_length'],
|
340 |
+
helix_bias=params['helix_bias'],
|
341 |
+
strand_bias=params['strand_bias'],
|
342 |
+
loop_bias=params['loop_bias'],
|
343 |
+
secondary_structure=None,
|
344 |
+
aa_bias=None,
|
345 |
+
aa_bias_potential=None,
|
346 |
+
num_steps="25",
|
347 |
+
noise="normal",
|
348 |
+
hydrophobic_target_score=str(params['hydrophobic_target_score']),
|
349 |
+
hydrophobic_potential="2",
|
350 |
+
contigs=None,
|
351 |
+
pssm=None,
|
352 |
+
seq_mask=None,
|
353 |
+
str_mask=None,
|
354 |
+
rewrite_pdb=None
|
355 |
+
)
|
356 |
+
return result
|
357 |
+
|
358 |
+
def generate_explanation(result, params):
|
359 |
+
explanation = f"""
|
360 |
+
์์ฑ๋ ๋จ๋ฐฑ์ง ๋ถ์:
|
361 |
+
- ๊ธธ์ด: {params['sequence_length']} ์๋ฏธ๋
ธ์ฐ
|
362 |
+
- ๊ตฌ์กฐ์ ํน์ง:
|
363 |
+
* ์ํ ๋์ ๋น์จ: {params['helix_bias']*100}%
|
364 |
+
* ๋ฒ ํ ์ํธ ๋น์จ: {params['strand_bias']*100}%
|
365 |
+
* ๋ฃจํ ๊ตฌ์กฐ ๋น์จ: {params['loop_bias']*100}%
|
366 |
+
- ํน์ ๊ธฐ๋ฅ: {result.get('special_features', '์์')}
|
367 |
+
"""
|
368 |
+
return explanation
|
369 |
+
|
370 |
+
# ์ฒดํฌํฌ์ธํธ ํ์ผ ๊ฒฝ๋ก๋ฅผ ์ ๋ ๊ฒฝ๋ก๋ก ์์
|
371 |
+
def protein_diffusion_model(sequence, seq_len, helix_bias, strand_bias, loop_bias,
|
372 |
+
secondary_structure, aa_bias, aa_bias_potential,
|
373 |
+
num_steps, noise, hydrophobic_target_score, hydrophobic_potential,
|
374 |
+
contigs, pssm, seq_mask, str_mask, rewrite_pdb):
|
375 |
+
|
376 |
+
|
377 |
+
dssp_checkpoint = './SEQDIFF_230205_dssp_hotspots_25mask_EQtasks_mod30.pt'
|
378 |
+
og_checkpoint = './SEQDIFF_221219_equalTASKS_nostrSELFCOND_mod30.pt'
|
379 |
+
|
380 |
+
|
381 |
+
# ์ฒดํฌํฌ์ธํธ ํ์ผ ์กด์ฌ ํ์ธ
|
382 |
+
if not os.path.exists(dssp_checkpoint):
|
383 |
+
raise FileNotFoundError(f"DSSP checkpoint file not found at: {dssp_checkpoint}")
|
384 |
+
if not os.path.exists(og_checkpoint):
|
385 |
+
raise FileNotFoundError(f"OG checkpoint file not found at: {og_checkpoint}")
|
386 |
+
|
387 |
+
model_args = copy.deepcopy(args)
|
388 |
+
|
389 |
+
|
390 |
+
# make sampler
|
391 |
+
S = HuggingFace_sampler(args=model_args)
|
392 |
+
|
393 |
+
# get random prefix
|
394 |
+
S.out_prefix = './tmp/'+secrets.token_hex(nbytes=10).upper()
|
395 |
+
|
396 |
+
# set args
|
397 |
+
S.args['checkpoint'] = None
|
398 |
+
S.args['dump_trb'] = False
|
399 |
+
S.args['dump_args'] = True
|
400 |
+
S.args['save_best_plddt'] = True
|
401 |
+
S.args['T'] = 25
|
402 |
+
S.args['strand_bias'] = 0.0
|
403 |
+
S.args['loop_bias'] = 0.0
|
404 |
+
S.args['helix_bias'] = 0.0
|
405 |
+
S.args['potentials'] = None
|
406 |
+
S.args['potential_scale'] = None
|
407 |
+
S.args['aa_composition'] = None
|
408 |
+
|
409 |
+
|
410 |
+
# get sequence if entered and make sure all chars are valid
|
411 |
+
alt_aa_dict = {'B':['D','N'],'J':['I','L'],'U':['C'],'Z':['E','Q'],'O':['K']}
|
412 |
+
if sequence not in ['',None]:
|
413 |
+
L = len(sequence)
|
414 |
+
aa_seq = []
|
415 |
+
for aa in sequence.upper():
|
416 |
+
if aa in alt_aa_dict.keys():
|
417 |
+
aa_seq.append(np.random.choice(alt_aa_dict[aa]))
|
418 |
+
else:
|
419 |
+
aa_seq.append(aa)
|
420 |
+
|
421 |
+
S.args['sequence'] = aa_seq
|
422 |
+
elif contigs not in ['',None]:
|
423 |
+
S.args['contigs'] = [contigs]
|
424 |
+
else:
|
425 |
+
S.args['contigs'] = [f'{seq_len}']
|
426 |
+
L = int(seq_len)
|
427 |
+
|
428 |
+
print('DEBUG: ',rewrite_pdb)
|
429 |
+
if rewrite_pdb not in ['',None]:
|
430 |
+
S.args['pdb'] = rewrite_pdb.name
|
431 |
+
|
432 |
+
if seq_mask not in ['',None]:
|
433 |
+
S.args['inpaint_seq'] = [seq_mask]
|
434 |
+
if str_mask not in ['',None]:
|
435 |
+
S.args['inpaint_str'] = [str_mask]
|
436 |
+
|
437 |
+
if secondary_structure in ['',None]:
|
438 |
+
secondary_structure = None
|
439 |
+
else:
|
440 |
+
secondary_structure = ''.join(['E' if x == 'S' else x for x in secondary_structure])
|
441 |
+
if L < len(secondary_structure):
|
442 |
+
secondary_structure = secondary_structure[:len(sequence)]
|
443 |
+
elif L == len(secondary_structure):
|
444 |
+
pass
|
445 |
+
else:
|
446 |
+
dseq = L - len(secondary_structure)
|
447 |
+
secondary_structure += secondary_structure[-1]*dseq
|
448 |
+
|
449 |
+
|
450 |
+
# potentials
|
451 |
+
potential_list = []
|
452 |
+
potential_bias_list = []
|
453 |
+
|
454 |
+
if aa_bias not in ['',None]:
|
455 |
+
potential_list.append('aa_bias')
|
456 |
+
S.args['aa_composition'] = aa_bias
|
457 |
+
if aa_bias_potential in ['',None]:
|
458 |
+
aa_bias_potential = 3
|
459 |
+
potential_bias_list.append(str(aa_bias_potential))
|
460 |
+
'''
|
461 |
+
if target_charge not in ['',None]:
|
462 |
+
potential_list.append('charge')
|
463 |
+
if charge_potential in ['',None]:
|
464 |
+
charge_potential = 1
|
465 |
+
potential_bias_list.append(str(charge_potential))
|
466 |
+
S.args['target_charge'] = float(target_charge)
|
467 |
+
if target_ph in ['',None]:
|
468 |
+
target_ph = 7.4
|
469 |
+
S.args['target_pH'] = float(target_ph)
|
470 |
+
'''
|
471 |
+
|
472 |
+
if hydrophobic_target_score not in ['',None]:
|
473 |
+
potential_list.append('hydrophobic')
|
474 |
+
S.args['hydrophobic_score'] = float(hydrophobic_target_score)
|
475 |
+
if hydrophobic_potential in ['',None]:
|
476 |
+
hydrophobic_potential = 3
|
477 |
+
potential_bias_list.append(str(hydrophobic_potential))
|
478 |
+
|
479 |
+
if pssm not in ['',None]:
|
480 |
+
potential_list.append('PSSM')
|
481 |
+
potential_bias_list.append('5')
|
482 |
+
S.args['PSSM'] = pssm.name
|
483 |
+
|
484 |
+
|
485 |
+
if len(potential_list) > 0:
|
486 |
+
S.args['potentials'] = ','.join(potential_list)
|
487 |
+
S.args['potential_scale'] = ','.join(potential_bias_list)
|
488 |
+
|
489 |
+
|
490 |
+
# normalise secondary_structure bias from range 0-0.3
|
491 |
+
S.args['secondary_structure'] = secondary_structure
|
492 |
+
S.args['helix_bias'] = helix_bias
|
493 |
+
S.args['strand_bias'] = strand_bias
|
494 |
+
S.args['loop_bias'] = loop_bias
|
495 |
+
|
496 |
+
# set T
|
497 |
+
if num_steps in ['',None]:
|
498 |
+
S.args['T'] = 20
|
499 |
+
else:
|
500 |
+
S.args['T'] = int(num_steps)
|
501 |
+
|
502 |
+
# noise
|
503 |
+
if 'normal' in noise:
|
504 |
+
S.args['sample_distribution'] = noise
|
505 |
+
S.args['sample_distribution_gmm_means'] = [0]
|
506 |
+
S.args['sample_distribution_gmm_variances'] = [1]
|
507 |
+
elif 'gmm2' in noise:
|
508 |
+
S.args['sample_distribution'] = noise
|
509 |
+
S.args['sample_distribution_gmm_means'] = [-1,1]
|
510 |
+
S.args['sample_distribution_gmm_variances'] = [1,1]
|
511 |
+
elif 'gmm3' in noise:
|
512 |
+
S.args['sample_distribution'] = noise
|
513 |
+
S.args['sample_distribution_gmm_means'] = [-1,0,1]
|
514 |
+
S.args['sample_distribution_gmm_variances'] = [1,1,1]
|
515 |
+
|
516 |
+
|
517 |
+
|
518 |
+
if secondary_structure not in ['',None] or helix_bias+strand_bias+loop_bias > 0:
|
519 |
+
S.args['checkpoint'] = dssp_checkpoint
|
520 |
+
S.args['d_t1d'] = 29
|
521 |
+
print('using dssp checkpoint')
|
522 |
+
else:
|
523 |
+
S.args['checkpoint'] = og_checkpoint
|
524 |
+
S.args['d_t1d'] = 24
|
525 |
+
print('using og checkpoint')
|
526 |
+
|
527 |
+
|
528 |
+
for k,v in S.args.items():
|
529 |
+
print(f"{k} --> {v}")
|
530 |
+
|
531 |
+
# init S
|
532 |
+
S.model_init()
|
533 |
+
S.diffuser_init()
|
534 |
+
S.setup()
|
535 |
+
|
536 |
+
# sampling loop
|
537 |
+
plddt_data = []
|
538 |
+
for j in range(S.max_t):
|
539 |
+
print(f'on step {j}')
|
540 |
+
output_seq, output_pdb, plddt = S.take_step_get_outputs(j)
|
541 |
+
plddt_data.append(plddt)
|
542 |
+
yield output_seq, output_pdb, display_pdb(output_pdb), get_plddt_plot(plddt_data, S.max_t)
|
543 |
+
|
544 |
+
output_seq, output_pdb, plddt = S.get_outputs()
|
545 |
+
|
546 |
+
return output_seq, output_pdb, display_pdb(output_pdb), get_plddt_plot(plddt_data, S.max_t)
|
547 |
+
|
548 |
+
def get_plddt_plot(plddt_data, max_t):
|
549 |
+
fig, ax = plt.subplots(figsize=(15,6))
|
550 |
+
x = list(range(1, len(plddt_data) + 1))
|
551 |
+
ax.plot(x, plddt_data, color='#661dbf', linewidth=3, marker='o')
|
552 |
+
ax.set_xticks(range(1, max_t + 1))
|
553 |
+
ax.set_yticks([i/10 for i in range(11)]) # 0๋ถํฐ 1๊น์ง
|
554 |
+
ax.set_ylim([0, 1])
|
555 |
+
ax.set_ylabel('model confidence (plddt)')
|
556 |
+
ax.set_xlabel('diffusion steps (t)')
|
557 |
+
plt.close() # ๋ฉ๋ชจ๋ฆฌ ๊ด๋ฆฌ๋ฅผ ์ํด ๋ซ๊ธฐ
|
558 |
+
return fig
|
559 |
+
|
560 |
+
|
561 |
+
def display_pdb(path_to_pdb):
|
562 |
+
'''
|
563 |
+
#function to display pdb in py3dmol
|
564 |
+
'''
|
565 |
+
pdb = open(path_to_pdb, "r").read()
|
566 |
+
|
567 |
+
view = py3Dmol.view(width=500, height=500)
|
568 |
+
view.addModel(pdb, "pdb")
|
569 |
+
view.setStyle({'model': -1}, {"cartoon": {'colorscheme':{'prop':'b','gradient':'roygb','min':0,'max':1}}})#'linear', 'min': 0, 'max': 1, 'colors': ["#ff9ef0","#a903fc",]}}})
|
570 |
+
view.zoomTo()
|
571 |
+
output = view._make_html().replace("'", '"')
|
572 |
+
print(view._make_html())
|
573 |
+
x = f"""<!DOCTYPE html><html></center> {output} </center></html>""" # do not use ' in this input
|
574 |
+
|
575 |
+
return f"""<iframe height="500px" width="100%" name="result" allow="midi; geolocation; microphone; camera;
|
576 |
+
display-capture; encrypted-media;" sandbox="allow-modals allow-forms
|
577 |
+
allow-scripts allow-same-origin allow-popups
|
578 |
+
allow-top-navigation-by-user-activation allow-downloads" allowfullscreen=""
|
579 |
+
allowpaymentrequest="" frameborder="0" srcdoc='{x}'></iframe>"""
|
580 |
+
|
581 |
+
'''
|
582 |
+
return f"""<iframe style="width: 100%; height:700px" name="result" allow="midi; geolocation; microphone; camera;
|
583 |
+
display-capture; encrypted-media;" sandbox="allow-modals allow-forms
|
584 |
+
allow-scripts allow-same-origin allow-popups
|
585 |
+
allow-top-navigation-by-user-activation allow-downloads" allowfullscreen=""
|
586 |
+
allowpaymentrequest="" frameborder="0" srcdoc='{x}'></iframe>"""
|
587 |
+
'''
|
588 |
+
|
589 |
+
def get_motif_preview(pdb_id, contigs):
|
590 |
+
try:
|
591 |
+
input_pdb = fetch_pdb(pdb_id=pdb_id.lower() if pdb_id else None)
|
592 |
+
if input_pdb is None:
|
593 |
+
return gr.HTML("PDB ID๋ฅผ ์
๋ ฅํด์ฃผ์ธ์"), None
|
594 |
+
|
595 |
+
parse = parse_pdb(input_pdb)
|
596 |
+
output_name = input_pdb
|
597 |
+
|
598 |
+
pdb = open(output_name, "r").read()
|
599 |
+
view = py3Dmol.view(width=500, height=500)
|
600 |
+
view.addModel(pdb, "pdb")
|
601 |
+
|
602 |
+
if contigs in ['',0]:
|
603 |
+
contigs = ['0']
|
604 |
+
else:
|
605 |
+
contigs = [contigs]
|
606 |
+
|
607 |
+
print('DEBUG: ',contigs)
|
608 |
+
|
609 |
+
pdb_map = get_mappings(ContigMap(parse,contigs))
|
610 |
+
print('DEBUG: ',pdb_map)
|
611 |
+
print('DEBUG: ',pdb_map['con_ref_idx0'])
|
612 |
+
roi = [x[1]-1 for x in pdb_map['con_ref_pdb_idx']]
|
613 |
+
|
614 |
+
colormap = {0:'#D3D3D3', 1:'#F74CFF'}
|
615 |
+
colors = {i+1: colormap[1] if i in roi else colormap[0] for i in range(parse['xyz'].shape[0])}
|
616 |
+
view.setStyle({"cartoon": {"colorscheme": {"prop": "resi", "map": colors}}})
|
617 |
+
view.zoomTo()
|
618 |
+
output = view._make_html().replace("'", '"')
|
619 |
+
print(view._make_html())
|
620 |
+
x = f"""<!DOCTYPE html><html></center> {output} </center></html>""" # do not use ' in this input
|
621 |
+
|
622 |
+
return f"""<iframe height="500px" width="100%" name="result" allow="midi; geolocation; microphone; camera;
|
623 |
+
display-capture; encrypted-media;" sandbox="allow-modals allow-forms
|
624 |
+
allow-scripts allow-same-origin allow-popups
|
625 |
+
allow-top-navigation-by-user-activation allow-downloads" allowfullscreen=""
|
626 |
+
allowpaymentrequest="" frameborder="0" srcdoc='{x}'></iframe>""", output_name
|
627 |
+
|
628 |
+
except Exception as e:
|
629 |
+
return gr.HTML(f"์ค๋ฅ๊ฐ ๋ฐ์ํ์ต๋๋ค: {str(e)}"), None
|
630 |
+
|
631 |
+
def fetch_pdb(pdb_id=None):
|
632 |
+
if pdb_id is None or pdb_id == "":
|
633 |
+
return None
|
634 |
+
else:
|
635 |
+
os.system(f"wget -qnc https://files.rcsb.org/view/{pdb_id}.pdb")
|
636 |
+
return f"{pdb_id}.pdb"
|
637 |
+
|
638 |
+
# MSA AND PSSM GUIDANCE
|
639 |
+
def save_pssm(file_upload):
|
640 |
+
filename = file_upload.name
|
641 |
+
orig_name = file_upload.orig_name
|
642 |
+
if filename.split('.')[-1] in ['fasta', 'a3m']:
|
643 |
+
return msa_to_pssm(file_upload)
|
644 |
+
return filename
|
645 |
+
|
646 |
+
def msa_to_pssm(msa_file):
|
647 |
+
# Define the lookup table for converting amino acids to indices
|
648 |
+
aa_to_index = {'A': 0, 'R': 1, 'N': 2, 'D': 3, 'C': 4, 'Q': 5, 'E': 6, 'G': 7, 'H': 8, 'I': 9, 'L': 10,
|
649 |
+
'K': 11, 'M': 12, 'F': 13, 'P': 14, 'S': 15, 'T': 16, 'W': 17, 'Y': 18, 'V': 19, 'X': 20, '-': 21}
|
650 |
+
# Open the FASTA file and read the sequences
|
651 |
+
records = list(SeqIO.parse(msa_file.name, "fasta"))
|
652 |
+
|
653 |
+
assert len(records) >= 1, "MSA must contain more than one protein sequecne."
|
654 |
+
|
655 |
+
first_seq = str(records[0].seq)
|
656 |
+
aligned_seqs = [first_seq]
|
657 |
+
# print(aligned_seqs)
|
658 |
+
# Perform sequence alignment using the Needleman-Wunsch algorithm
|
659 |
+
aligner = Align.PairwiseAligner()
|
660 |
+
aligner.open_gap_score = -0.7
|
661 |
+
aligner.extend_gap_score = -0.3
|
662 |
+
for record in records[1:]:
|
663 |
+
alignment = aligner.align(first_seq, str(record.seq))[0]
|
664 |
+
alignment = alignment.format().split("\n")
|
665 |
+
al1 = alignment[0]
|
666 |
+
al2 = alignment[2]
|
667 |
+
al1_fin = ""
|
668 |
+
al2_fin = ""
|
669 |
+
percent_gap = al2.count('-')/ len(al2)
|
670 |
+
if percent_gap > 0.4:
|
671 |
+
continue
|
672 |
+
for i in range(len(al1)):
|
673 |
+
if al1[i] != '-':
|
674 |
+
al1_fin += al1[i]
|
675 |
+
al2_fin += al2[i]
|
676 |
+
aligned_seqs.append(str(al2_fin))
|
677 |
+
# Get the length of the aligned sequences
|
678 |
+
aligned_seq_length = len(first_seq)
|
679 |
+
# Initialize the position scoring matrix
|
680 |
+
matrix = np.zeros((22, aligned_seq_length))
|
681 |
+
# Iterate through the aligned sequences and count the amino acids at each position
|
682 |
+
for seq in aligned_seqs:
|
683 |
+
#print(seq)
|
684 |
+
for i in range(aligned_seq_length):
|
685 |
+
if i == len(seq):
|
686 |
+
break
|
687 |
+
amino_acid = seq[i]
|
688 |
+
if amino_acid.upper() not in aa_to_index.keys():
|
689 |
+
continue
|
690 |
+
else:
|
691 |
+
aa_index = aa_to_index[amino_acid.upper()]
|
692 |
+
matrix[aa_index, i] += 1
|
693 |
+
# Normalize the counts to get the frequency of each amino acid at each position
|
694 |
+
matrix /= len(aligned_seqs)
|
695 |
+
print(len(aligned_seqs))
|
696 |
+
matrix[20:,]=0
|
697 |
+
|
698 |
+
outdir = ".".join(msa_file.name.split('.')[:-1]) + ".csv"
|
699 |
+
np.savetxt(outdir, matrix[:21,:].T, delimiter=",")
|
700 |
+
return outdir
|
701 |
+
|
702 |
+
def get_pssm(fasta_msa, input_pssm):
|
703 |
+
try:
|
704 |
+
if input_pssm is not None:
|
705 |
+
outdir = input_pssm.name
|
706 |
+
elif fasta_msa is not None:
|
707 |
+
outdir = save_pssm(fasta_msa)
|
708 |
+
else:
|
709 |
+
return gr.Plot(label="ํ์ผ์ ์
๋ก๋ํด์ฃผ์ธ์"), None
|
710 |
+
|
711 |
+
pssm = np.loadtxt(outdir, delimiter=",", dtype=float)
|
712 |
+
fig, ax = plt.subplots(figsize=(15,6))
|
713 |
+
plt.imshow(torch.permute(torch.tensor(pssm),(1,0)))
|
714 |
+
return fig, outdir
|
715 |
+
except Exception as e:
|
716 |
+
return gr.Plot(label=f"์ค๋ฅ๊ฐ ๋ฐ์ํ์ต๋๋ค: {str(e)}"), None
|
717 |
+
|
718 |
+
# ํ์ด๋ก ๋ฅ๋ ฅ์น ๊ณ์ฐ ํจ์ ์ถ๊ฐ
|
719 |
+
def calculate_hero_stats(helix_bias, strand_bias, loop_bias, hydrophobic_score):
|
720 |
+
stats = {
|
721 |
+
'strength': strand_bias * 20, # ๋ฒ ํ์ํธ ๊ตฌ์กฐ ๊ธฐ๋ฐ
|
722 |
+
'flexibility': helix_bias * 20, # ์ํํฌ๋ฆญ์ค ๊ตฌ์กฐ ๊ธฐ๋ฐ
|
723 |
+
'speed': loop_bias * 5, # ๋ฃจํ ๊ตฌ์กฐ ๊ธฐ๋ฐ
|
724 |
+
'defense': abs(hydrophobic_score) if hydrophobic_score else 0
|
725 |
+
}
|
726 |
+
return stats
|
727 |
+
|
728 |
+
def toggle_seq_input(choice):
|
729 |
+
if choice == "์๋ ์ค๊ณ":
|
730 |
+
return gr.update(visible=True), gr.update(visible=False)
|
731 |
+
else: # "์ง์ ์
๋ ฅ"
|
732 |
+
return gr.update(visible=False), gr.update(visible=True)
|
733 |
+
|
734 |
+
def toggle_secondary_structure(choice):
|
735 |
+
if choice == "์ฌ๋ผ์ด๋๋ก ์ค์ ":
|
736 |
+
return (
|
737 |
+
gr.update(visible=True), # helix_bias
|
738 |
+
gr.update(visible=True), # strand_bias
|
739 |
+
gr.update(visible=True), # loop_bias
|
740 |
+
gr.update(visible=False) # secondary_structure
|
741 |
+
)
|
742 |
+
else: # "์ง์ ์
๋ ฅ"
|
743 |
+
return (
|
744 |
+
gr.update(visible=False), # helix_bias
|
745 |
+
gr.update(visible=False), # strand_bias
|
746 |
+
gr.update(visible=False), # loop_bias
|
747 |
+
gr.update(visible=True) # secondary_structure
|
748 |
+
)
|
749 |
+
|
750 |
+
|
751 |
+
def create_radar_chart(stats):
|
752 |
+
# ๋ ์ด๋ ์ฐจํธ ์์ฑ ๋ก์ง
|
753 |
+
categories = list(stats.keys())
|
754 |
+
values = list(stats.values())
|
755 |
+
|
756 |
+
fig = go.Figure(data=go.Scatterpolar(
|
757 |
+
r=values,
|
758 |
+
theta=categories,
|
759 |
+
fill='toself'
|
760 |
+
))
|
761 |
+
|
762 |
+
fig.update_layout(
|
763 |
+
polar=dict(
|
764 |
+
radialaxis=dict(
|
765 |
+
visible=True,
|
766 |
+
range=[0, 1]
|
767 |
+
)),
|
768 |
+
showlegend=False
|
769 |
+
)
|
770 |
+
|
771 |
+
return fig
|
772 |
+
|
773 |
+
def generate_hero_description(name, stats, abilities):
|
774 |
+
# ํ์ด๋ก ์ค๋ช
์์ฑ ๋ก์ง
|
775 |
+
description = f"""
|
776 |
+
ํ์ด๋ก ์ด๋ฆ: {name}
|
777 |
+
|
778 |
+
์ฃผ์ ๋ฅ๋ ฅ:
|
779 |
+
- ๊ทผ๋ ฅ: {'โ
' * int(stats['strength'] * 5)}
|
780 |
+
- ์ ์ฐ์ฑ: {'โ
' * int(stats['flexibility'] * 5)}
|
781 |
+
- ์คํผ๋: {'โ
' * int(stats['speed'] * 5)}
|
782 |
+
- ๋ฐฉ์ด๋ ฅ: {'โ
' * int(stats['defense'] * 5)}
|
783 |
+
|
784 |
+
ํน์ ๋ฅ๋ ฅ: {', '.join(abilities)}
|
785 |
+
"""
|
786 |
+
return description
|
787 |
+
|
788 |
+
def combined_generation(name, strength, flexibility, speed, defense, size, abilities,
|
789 |
+
sequence, seq_len, helix_bias, strand_bias, loop_bias,
|
790 |
+
secondary_structure, aa_bias, aa_bias_potential,
|
791 |
+
num_steps, noise, hydrophobic_target_score, hydrophobic_potential,
|
792 |
+
contigs, pssm, seq_mask, str_mask, rewrite_pdb):
|
793 |
+
try:
|
794 |
+
# protein_diffusion_model ์คํ
|
795 |
+
generator = protein_diffusion_model(
|
796 |
+
sequence=None,
|
797 |
+
seq_len=size, # ํ์ด๋ก ํฌ๊ธฐ๋ฅผ seq_len์ผ๋ก ์ฌ์ฉ
|
798 |
+
helix_bias=flexibility, # ํ์ด๋ก ์ ์ฐ์ฑ์ helix_bias๋ก ์ฌ์ฉ
|
799 |
+
strand_bias=strength, # ํ์ด๋ก ๊ฐ๋๋ฅผ strand_bias๋ก ์ฌ์ฉ
|
800 |
+
loop_bias=speed, # ํ์ด๋ก ์คํผ๋๋ฅผ loop_bias๋ก ์ฌ์ฉ
|
801 |
+
secondary_structure=None,
|
802 |
+
aa_bias=None,
|
803 |
+
aa_bias_potential=None,
|
804 |
+
num_steps="25",
|
805 |
+
noise="normal",
|
806 |
+
hydrophobic_target_score=str(-defense), # ํ์ด๋ก ๋ฐฉ์ด๋ ฅ์ hydrophobic score๋ก ์ฌ์ฉ
|
807 |
+
hydrophobic_potential="2",
|
808 |
+
contigs=None,
|
809 |
+
pssm=None,
|
810 |
+
seq_mask=None,
|
811 |
+
str_mask=None,
|
812 |
+
rewrite_pdb=None
|
813 |
+
)
|
814 |
+
|
815 |
+
# ๋ง์ง๋ง ๊ฒฐ๊ณผ ๊ฐ์ ธ์ค๊ธฐ
|
816 |
+
final_result = None
|
817 |
+
for result in generator:
|
818 |
+
final_result = result
|
819 |
+
|
820 |
+
if final_result is None:
|
821 |
+
raise Exception("์์ฑ ๊ฒฐ๊ณผ๊ฐ ์์ต๋๋ค")
|
822 |
+
|
823 |
+
output_seq, output_pdb, structure_view, plddt_plot = final_result
|
824 |
+
|
825 |
+
# ํ์ด๋ก ๋ฅ๋ ฅ์น ๊ณ์ฐ
|
826 |
+
stats = calculate_hero_stats(flexibility, strength, speed, defense)
|
827 |
+
|
828 |
+
# ๋ชจ๋ ๊ฒฐ๊ณผ ๋ฐํ
|
829 |
+
return (
|
830 |
+
create_radar_chart(stats), # ๋ฅ๋ ฅ์น ์ฐจํธ
|
831 |
+
generate_hero_description(name, stats, abilities), # ํ์ด๋ก ์ค๋ช
|
832 |
+
output_seq, # ๋จ๋ฐฑ์ง ์์ด
|
833 |
+
output_pdb, # PDB ํ์ผ
|
834 |
+
structure_view, # 3D ๊ตฌ์กฐ
|
835 |
+
plddt_plot # ์ ๋ขฐ๋ ์ฐจํธ
|
836 |
+
)
|
837 |
+
except Exception as e:
|
838 |
+
print(f"Error in combined_generation: {str(e)}")
|
839 |
+
return (
|
840 |
+
None,
|
841 |
+
f"์๋ฌ: {str(e)}",
|
842 |
+
None,
|
843 |
+
None,
|
844 |
+
gr.HTML("์๋ฌ๊ฐ ๋ฐ์ํ์ต๋๋ค"),
|
845 |
+
None
|
846 |
+
)
|
847 |
+
|
848 |
+
|
849 |
+
def extract_parameters_from_chat(chat_response):
|
850 |
+
"""์ฑ๋ด ์๋ต์์ ํ๋ผ๋ฏธํฐ ์ถ์ถ"""
|
851 |
+
try:
|
852 |
+
params = {
|
853 |
+
'sequence_length': 100,
|
854 |
+
'helix_bias': 0.02,
|
855 |
+
'strand_bias': 0.02,
|
856 |
+
'loop_bias': 0.1,
|
857 |
+
'hydrophobic_target_score': 0
|
858 |
+
}
|
859 |
+
|
860 |
+
# ์๋ต ํ
์คํธ์์ ๊ฐ ์ถ์ถ
|
861 |
+
if "๊ธธ์ด:" in chat_response:
|
862 |
+
length_match = re.search(r'๊ธธ์ด: (\d+)', chat_response)
|
863 |
+
if length_match:
|
864 |
+
params['sequence_length'] = int(length_match.group(1))
|
865 |
+
|
866 |
+
if "์ํ ํฌ๋ฆญ์ค ๋น์จ:" in chat_response:
|
867 |
+
helix_match = re.search(r'์ํ ํฌ๋ฆญ์ค ๋น์จ: ([\d.]+)', chat_response)
|
868 |
+
if helix_match:
|
869 |
+
params['helix_bias'] = float(helix_match.group(1)) / 100
|
870 |
+
|
871 |
+
if "๋ฒ ํ ์ํธ ๋น์จ:" in chat_response:
|
872 |
+
strand_match = re.search(r'๋ฒ ํ ์ํธ ๋น์จ: ([\d.]+)', chat_response)
|
873 |
+
if strand_match:
|
874 |
+
params['strand_bias'] = float(strand_match.group(1)) / 100
|
875 |
+
|
876 |
+
if "๋ฃจํ ๊ตฌ์กฐ ๋น์จ:" in chat_response:
|
877 |
+
loop_match = re.search(r'๋ฃจํ ๊ตฌ์กฐ ๋น์จ: ([\d.]+)', chat_response)
|
878 |
+
if loop_match:
|
879 |
+
params['loop_bias'] = float(loop_match.group(1)) / 100
|
880 |
+
|
881 |
+
if "์์์ฑ ์ ์:" in chat_response:
|
882 |
+
hydro_match = re.search(r'์์์ฑ ์ ์: ([-\d.]+)', chat_response)
|
883 |
+
if hydro_match:
|
884 |
+
params['hydrophobic_target_score'] = float(hydro_match.group(1))
|
885 |
+
|
886 |
+
return params
|
887 |
+
except Exception as e:
|
888 |
+
print(f"ํ๋ผ๋ฏธํฐ ์ถ์ถ ์ค ์ค๋ฅ: {str(e)}")
|
889 |
+
return None
|
890 |
+
|
891 |
+
def update_protein_display(chat_response):
|
892 |
+
if "์์ฑ๋ ๋จ๋ฐฑ์ง ๋ถ์" in chat_response:
|
893 |
+
params = extract_parameters_from_chat(chat_response)
|
894 |
+
if params:
|
895 |
+
result = generate_protein(params)
|
896 |
+
stats = calculate_hero_stats(
|
897 |
+
helix_bias=params['helix_bias'],
|
898 |
+
strand_bias=params['strand_bias'],
|
899 |
+
loop_bias=params['loop_bias'],
|
900 |
+
hydrophobic_score=params['hydrophobic_target_score']
|
901 |
+
)
|
902 |
+
return {
|
903 |
+
hero_stats: create_radar_chart(stats),
|
904 |
+
hero_description: chat_response,
|
905 |
+
output_seq: result[0],
|
906 |
+
output_pdb: result[1],
|
907 |
+
output_viewer: display_pdb(result[1]),
|
908 |
+
plddt_plot: result[3]
|
909 |
+
}
|
910 |
+
return None
|
911 |
+
|
912 |
+
def analyze_active_sites(sequence):
|
913 |
+
"""ํ์ฑ ๋ถ์ ๋ถ์"""
|
914 |
+
return "๋ถ์ ์ค..." # ์์ ๊ตฌํ
|
915 |
+
|
916 |
+
def predict_interactions(params):
|
917 |
+
"""์ํธ์์ฉ ์์ธก"""
|
918 |
+
return "์์ธก ์ค..." # ์์ ๊ตฌํ
|
919 |
+
|
920 |
+
def evaluate_stability(plddt_data):
|
921 |
+
"""์์ ์ฑ ํ๊ฐ"""
|
922 |
+
if not plddt_data:
|
923 |
+
return "ํ๊ฐ ๋ถ๊ฐ"
|
924 |
+
avg_score = np.mean(plddt_data)
|
925 |
+
if avg_score > 0.8:
|
926 |
+
return "๋งค์ฐ ์์ ์ "
|
927 |
+
elif avg_score > 0.6:
|
928 |
+
return "์์ ์ "
|
929 |
+
else:
|
930 |
+
return "๋ณดํต"
|
931 |
+
|
932 |
+
def process_chat_and_generate(message, history):
|
933 |
+
try:
|
934 |
+
# 1. ์ด๊ธฐ ์๋ต ์์ฑ
|
935 |
+
initial_response = "๋จ๋ฐฑ์ง ์ค๊ณ๋ฅผ ์์ํฉ๋๋ค. ์ ์๋ง ๊ธฐ๋ค๋ ค์ฃผ์ธ์..."
|
936 |
+
yield (
|
937 |
+
history + [
|
938 |
+
{"role": "user", "content": message},
|
939 |
+
{"role": "assistant", "content": initial_response}
|
940 |
+
],
|
941 |
+
None, None, None, None, None, None
|
942 |
+
)
|
943 |
+
|
944 |
+
# 2. ํ๋กฌํํธ ๋ถ์
|
945 |
+
analysis = analyze_prompt(message)
|
946 |
+
similar_structures = search_protein_data(analysis, ds)
|
947 |
+
params = extract_parameters(analysis, similar_structures)
|
948 |
+
|
949 |
+
# 3. ๋จ๋ฐฑ์ง ์์ฑ ์์ ๋ฉ์์ง
|
950 |
+
progress_msg = "๋จ๋ฐฑ์ง ๊ตฌ์กฐ ์์ฑ์ ์์ํฉ๋๋ค..."
|
951 |
+
yield (
|
952 |
+
history + [
|
953 |
+
{"role": "user", "content": message},
|
954 |
+
{"role": "assistant", "content": progress_msg}
|
955 |
+
],
|
956 |
+
None, None, None, None, None, None
|
957 |
+
)
|
958 |
+
|
959 |
+
# 4. ๋จ๋ฐฑ์ง ์์ฑ
|
960 |
+
generator = protein_diffusion_model(
|
961 |
+
sequence=None,
|
962 |
+
seq_len=params['sequence_length'],
|
963 |
+
helix_bias=params['helix_bias'],
|
964 |
+
strand_bias=params['strand_bias'],
|
965 |
+
loop_bias=params['loop_bias'],
|
966 |
+
secondary_structure=None,
|
967 |
+
aa_bias=None,
|
968 |
+
aa_bias_potential=None,
|
969 |
+
num_steps="25",
|
970 |
+
noise="normal",
|
971 |
+
hydrophobic_target_score=str(params['hydrophobic_target_score']),
|
972 |
+
hydrophobic_potential="2",
|
973 |
+
contigs=None,
|
974 |
+
pssm=None,
|
975 |
+
seq_mask=None,
|
976 |
+
str_mask=None,
|
977 |
+
rewrite_pdb=None
|
978 |
+
)
|
979 |
+
|
980 |
+
# 5. ์์ฑ ๊ณผ์ ์ถ์
|
981 |
+
final_result = None
|
982 |
+
plddt_data = []
|
983 |
+
step = 0
|
984 |
+
|
985 |
+
for result in generator:
|
986 |
+
step += 1
|
987 |
+
final_result = result
|
988 |
+
if result[3]: # plddt_plot์ด ์กด์ฌํ๋ ๊ฒฝ์ฐ
|
989 |
+
ax = result[3].gca()
|
990 |
+
if ax.lines:
|
991 |
+
line = ax.lines[0]
|
992 |
+
plddt_data = line.get_ydata().tolist()
|
993 |
+
|
994 |
+
progress_msg = f"๋จ๋ฐฑ์ง ์์ฑ ์ค... {step}/25 ๋จ๊ณ ์๋ฃ"
|
995 |
+
yield (
|
996 |
+
history + [
|
997 |
+
{"role": "user", "content": message},
|
998 |
+
{"role": "assistant", "content": progress_msg}
|
999 |
+
],
|
1000 |
+
create_radar_chart(calculate_hero_stats(
|
1001 |
+
params['helix_bias'],
|
1002 |
+
params['strand_bias'],
|
1003 |
+
params['loop_bias'],
|
1004 |
+
float(params['hydrophobic_target_score'])
|
1005 |
+
)),
|
1006 |
+
progress_msg,
|
1007 |
+
result[0], # output_seq
|
1008 |
+
result[1], # output_pdb
|
1009 |
+
result[2], # structure_view
|
1010 |
+
result[3] # plddt_plot
|
1011 |
+
)
|
1012 |
+
|
1013 |
+
# 6. ์ต์ข
๊ฒฐ๊ณผ ๋ฐ ์ค๋ช
์์ฑ
|
1014 |
+
if final_result:
|
1015 |
+
output_seq, output_pdb, structure_view, plddt_plot = final_result
|
1016 |
+
|
1017 |
+
final_explanation = f"""
|
1018 |
+
๋จ๋ฐฑ์ง ์ค๊ณ๊ฐ ์๋ฃ๋์์ต๋๋ค.
|
1019 |
+
|
1020 |
+
[๋ถ์ ๊ฒฐ๊ณผ]
|
1021 |
+
{analysis}
|
1022 |
+
|
1023 |
+
[๊ตฌ์กฐ์ ํน์ง]
|
1024 |
+
- ๊ธธ์ด: {params['sequence_length']} ์๋ฏธ๋
ธ์ฐ
|
1025 |
+
- ์ํ ํฌ๋ฆญ์ค ๋น์จ: {params['helix_bias']*100:.1f}%
|
1026 |
+
- ๋ฒ ํ ์ํธ ๋น์จ: {params['strand_bias']*100:.1f}%
|
1027 |
+
- ๋ฃจํ ๊ตฌ์กฐ ๋น์จ: {params['loop_bias']*100:.1f}%
|
1028 |
+
- ์์์ฑ ์ ์: {params['hydrophobic_target_score']}
|
1029 |
+
|
1030 |
+
[์์ฑ ๊ณผ์ ]
|
1031 |
+
- ์ด {len(plddt_data)}๋จ๊ณ์ ์ต์ ํ ์๋ฃ
|
1032 |
+
- ์ต์ข
์์ ์ฑ ์ ์: {np.mean(plddt_data) if plddt_data else 0:.2f}
|
1033 |
+
- ์ฐธ์กฐ๋ ์ ์ฌ ๊ตฌ์กฐ: {len(similar_structures)}๊ฐ
|
1034 |
+
|
1035 |
+
3D ๊ตฌ์กฐ์ ์์ธ ๋ถ์ ๊ฒฐ๊ณผ๋ฅผ ํ์ธํ์ค ์ ์์ต๋๋ค.
|
1036 |
+
"""
|
1037 |
+
|
1038 |
+
return (
|
1039 |
+
history + [
|
1040 |
+
{"role": "user", "content": message},
|
1041 |
+
{"role": "assistant", "content": final_explanation}
|
1042 |
+
],
|
1043 |
+
create_radar_chart(calculate_hero_stats(
|
1044 |
+
params['helix_bias'],
|
1045 |
+
params['strand_bias'],
|
1046 |
+
params['loop_bias'],
|
1047 |
+
float(params['hydrophobic_target_score'])
|
1048 |
+
)),
|
1049 |
+
final_explanation,
|
1050 |
+
output_seq,
|
1051 |
+
output_pdb,
|
1052 |
+
structure_view,
|
1053 |
+
plddt_plot
|
1054 |
+
)
|
1055 |
+
|
1056 |
+
except Exception as e:
|
1057 |
+
print(f"Error in process_chat_and_generate: {str(e)}")
|
1058 |
+
traceback.print_exc()
|
1059 |
+
error_msg = f"์ค๋ฅ๊ฐ ๋ฐ์ํ์ต๋๋ค: {str(e)}"
|
1060 |
+
return (
|
1061 |
+
history + [
|
1062 |
+
{"role": "user", "content": message},
|
1063 |
+
{"role": "assistant", "content": error_msg}
|
1064 |
+
],
|
1065 |
+
None, None, None, None, None, None
|
1066 |
+
)
|
1067 |
+
|
1068 |
+
def extract_keywords(analysis):
|
1069 |
+
"""๋ถ์ ํ
์คํธ์์ ํค์๋ ์ถ์ถ"""
|
1070 |
+
try:
|
1071 |
+
# ๊ธฐ๋ณธ ํค์๋ ์ถ์ถ
|
1072 |
+
keywords = []
|
1073 |
+
# ์ฃผ์ ๊ธฐ๋ฅ ํค์๋
|
1074 |
+
if "์น๋ฃ" in analysis: keywords.extend(["therapeutic", "binding"])
|
1075 |
+
if "๊ฒฐํฉ" in analysis: keywords.extend(["binding", "interaction"])
|
1076 |
+
if "์ด๋งค" in analysis: keywords.extend(["enzyme", "catalytic"])
|
1077 |
+
|
1078 |
+
# ํ๊ฒฝ ํค์๋
|
1079 |
+
if "๋ง" in analysis: keywords.extend(["membrane", "transmembrane"])
|
1080 |
+
if "์์ฉ์ฑ" in analysis: keywords.extend(["soluble", "hydrophilic"])
|
1081 |
+
if "์์์ฑ" in analysis: keywords.extend(["hydrophobic"])
|
1082 |
+
|
1083 |
+
# ๊ตฌ์กฐ ํค์๋
|
1084 |
+
if "์ํ" in analysis or "๋์ " in analysis: keywords.append("helix")
|
1085 |
+
if "๋ฒ ํ" in analysis or "์ํธ" in analysis: keywords.append("sheet")
|
1086 |
+
if "๋ฃจํ" in analysis: keywords.append("loop")
|
1087 |
+
|
1088 |
+
return list(set(keywords)) # ์ค๋ณต ์ ๊ฑฐ
|
1089 |
+
except Exception as e:
|
1090 |
+
print(f"ํค์๋ ์ถ์ถ ์ค ์ค๋ฅ: {str(e)}")
|
1091 |
+
return []
|
1092 |
+
|
1093 |
+
def calculate_similarity(keywords, entry):
|
1094 |
+
"""ํค์๋์ ๋ฐ์ดํฐ์
ํญ๋ชฉ ๊ฐ์ ์ ์ฌ๋ ๊ณ์ฐ"""
|
1095 |
+
try:
|
1096 |
+
score = 0
|
1097 |
+
# ๋ฐ์ดํฐ์
๊ตฌ์กฐ ํ์ธ ๋ฐ ์์ ํ ์ ๊ทผ
|
1098 |
+
sequence = entry.get('sequence', '').lower() if isinstance(entry, dict) else str(entry).lower()
|
1099 |
+
|
1100 |
+
# ๋ฐ์ดํฐ์
๊ตฌ์กฐ ๋๋ฒ๊น
|
1101 |
+
print("Entry structure:", type(entry))
|
1102 |
+
print("Entry content:", entry)
|
1103 |
+
|
1104 |
+
for keyword in keywords:
|
1105 |
+
# ์์ ํ ์ ๊ทผ์ ์ํ ์์
|
1106 |
+
description = entry.get('description', '') if isinstance(entry, dict) else ''
|
1107 |
+
if keyword in description.lower():
|
1108 |
+
score += 2
|
1109 |
+
if keyword in sequence:
|
1110 |
+
score += 1
|
1111 |
+
if isinstance(entry, dict) and 'secondary_structure' in entry:
|
1112 |
+
sec_structure = entry['secondary_structure']
|
1113 |
+
if keyword in ['helix'] and 'H' in sec_structure:
|
1114 |
+
score += 1
|
1115 |
+
if keyword in ['sheet'] and 'E' in sec_structure:
|
1116 |
+
score += 1
|
1117 |
+
if keyword in ['loop'] and 'L' in sec_structure:
|
1118 |
+
score += 1
|
1119 |
+
return score
|
1120 |
+
except Exception as e:
|
1121 |
+
print(f"์ ์ฌ๋ ๊ณ์ฐ ์ค ์์ธ ์ค๋ฅ: {str(e)}")
|
1122 |
+
print("Entry:", entry)
|
1123 |
+
return 0
|
1124 |
+
|
1125 |
+
|
1126 |
+
|
1127 |
+
def download_checkpoint_files():
|
1128 |
+
"""ํ์ํ ์ฒดํฌํฌ์ธํธ ํ์ผ ๋ค์ด๋ก๋"""
|
1129 |
+
try:
|
1130 |
+
import requests
|
1131 |
+
|
1132 |
+
# ์ฒดํฌํฌ์ธํธ ํ์ผ URL (์ค์ URL๋ก ๊ต์ฒด ํ์)
|
1133 |
+
dssp_url = "YOUR_DSSP_CHECKPOINT_URL"
|
1134 |
+
og_url = "YOUR_OG_CHECKPOINT_URL"
|
1135 |
+
|
1136 |
+
# DSSP ์ฒดํฌํฌ์ธํธ ๋ค์ด๋ก๋
|
1137 |
+
if not os.path.exists(dssp_checkpoint):
|
1138 |
+
print("Downloading DSSP checkpoint...")
|
1139 |
+
response = requests.get(dssp_url)
|
1140 |
+
with open(dssp_checkpoint, 'wb') as f:
|
1141 |
+
f.write(response.content)
|
1142 |
+
|
1143 |
+
# OG ์ฒดํฌํฌ์ธํธ ๋ค์ด๋ก๋
|
1144 |
+
if not os.path.exists(og_checkpoint):
|
1145 |
+
print("Downloading OG checkpoint...")
|
1146 |
+
response = requests.get(og_url)
|
1147 |
+
with open(og_checkpoint, 'wb') as f:
|
1148 |
+
f.write(response.content)
|
1149 |
+
|
1150 |
+
print("Checkpoint files downloaded successfully")
|
1151 |
+
except Exception as e:
|
1152 |
+
print(f"Error downloading checkpoint files: {str(e)}")
|
1153 |
+
raise
|
1154 |
+
|
1155 |
+
# ์์ ์ ์ฒดํฌํฌ์ธํธ ํ์ผ ํ์ธ ๋ฐ ๋ค์ด๋ก๋
|
1156 |
+
try:
|
1157 |
+
download_checkpoint_files()
|
1158 |
+
except Exception as e:
|
1159 |
+
print(f"Warning: Could not download checkpoint files: {str(e)}")
|
1160 |
+
|
1161 |
+
with gr.Blocks(theme='ParityError/Interstellar') as demo:
|
1162 |
+
with gr.Row():
|
1163 |
+
with gr.Column(scale=1):
|
1164 |
+
# ์ฑ๋ด ์ธํฐํ์ด์ค
|
1165 |
+
gr.Markdown("# ๐ค AI ๋จ๋ฐฑ์ง ์ค๊ณ ๋์ฐ๋ฏธ")
|
1166 |
+
# ์ฌ๊ธฐ๋ฅผ ์์
|
1167 |
+
chatbot = gr.Chatbot(
|
1168 |
+
height=600,
|
1169 |
+
type='messages' # ๋ฉ์์ง ํ์ ์ง์
|
1170 |
+
|
1171 |
+
)
|
1172 |
+
with gr.Row():
|
1173 |
+
msg = gr.Textbox(
|
1174 |
+
label="๋ฉ์์ง๋ฅผ ์
๋ ฅํ์ธ์",
|
1175 |
+
placeholder="์: COVID-19๋ฅผ ์น๋ฃํ ์ ์๋ ๋จ๋ฐฑ์ง์ ์์ฑํด์ฃผ์ธ์",
|
1176 |
+
lines=2,
|
1177 |
+
scale=4
|
1178 |
+
)
|
1179 |
+
submit_btn = gr.Button("์ ์ก", variant="primary", scale=1)
|
1180 |
+
clear = gr.Button("๋ํ ๋ด์ฉ ์ง์ฐ๊ธฐ")
|
1181 |
+
|
1182 |
+
|
1183 |
+
|
1184 |
+
|
1185 |
+
with gr.Accordion("์ฑํ
์ค์ ", open=False):
|
1186 |
+
system_message = gr.Textbox(
|
1187 |
+
value="๋น์ ์ ๋จ๋ฐฑ์ง ์ค๊ณ๋ฅผ ๋์์ฃผ๋ ์ ๋ฌธ๊ฐ์
๋๋ค.",
|
1188 |
+
label="์์คํ
๋ฉ์์ง"
|
1189 |
+
)
|
1190 |
+
max_tokens = gr.Slider(
|
1191 |
+
minimum=1,
|
1192 |
+
maximum=3800,
|
1193 |
+
value=3800,
|
1194 |
+
step=1,
|
1195 |
+
label="์ต๋ ํ ํฐ ์"
|
1196 |
+
)
|
1197 |
+
temperature = gr.Slider(
|
1198 |
+
minimum=0.1,
|
1199 |
+
maximum=4.0,
|
1200 |
+
value=0.7,
|
1201 |
+
step=0.1,
|
1202 |
+
label="Temperature"
|
1203 |
+
)
|
1204 |
+
top_p = gr.Slider(
|
1205 |
+
minimum=0.1,
|
1206 |
+
maximum=1.0,
|
1207 |
+
value=0.95,
|
1208 |
+
step=0.05,
|
1209 |
+
label="Top-P"
|
1210 |
+
)
|
1211 |
+
|
1212 |
+
|
1213 |
+
# ํญ ์ธํฐํ์ด์ค
|
1214 |
+
with gr.Tabs():
|
1215 |
+
with gr.TabItem("๐ฆธโโ๏ธ ์ปค์คํ
๋์์ธ"):
|
1216 |
+
gr.Markdown("""
|
1217 |
+
### โจ ๋น์ ๋ง์ ํน๋ณํ ์ปค์คํ
์ ๋ง๋ค์ด๋ณด์ธ์!
|
1218 |
+
๊ฐ ๋ฅ๋ ฅ์น๋ฅผ ์กฐ์ ํ๋ฉด ์ปค์คํ
๋ ๋จ๋ฐฑ์ง์ด ์๋์ผ๋ก ์ค๊ณ๋ฉ๋๋ค.
|
1219 |
+
""")
|
1220 |
+
|
1221 |
+
# ํ์ด๋ก ๊ธฐ๋ณธ ์ ๋ณด
|
1222 |
+
hero_name = gr.Textbox(
|
1223 |
+
label="์ปค์คํ
์ด๋ฆ",
|
1224 |
+
placeholder="๋น์ ์ ์ปค์คํ
๋จ๋ฐฑ์ง ์ด๋ฆ์ ์ง์ด์ฃผ์ธ์!",
|
1225 |
+
info="๋น์ ๋ง์ ์ ์ฒด์ฑ์ ๋ํ๋ด๋ ์ด๋ฆ์ ์
๋ ฅํ์ธ์"
|
1226 |
+
)
|
1227 |
+
|
1228 |
+
# ๋ฅ๋ ฅ์น ์ค์
|
1229 |
+
gr.Markdown("### ๐ช ์ปค์คํ
๋ฅ๋ ฅ์น ์ค์ ")
|
1230 |
+
with gr.Row():
|
1231 |
+
strength = gr.Slider(
|
1232 |
+
minimum=0.0, maximum=0.05,
|
1233 |
+
label="๐ช ์ด๊ฐ๋ ฅ(๊ทผ๋ ฅ)",
|
1234 |
+
value=0.02,
|
1235 |
+
info="๋จ๋จํ ๋ฒ ํ์ํธ ๊ตฌ์กฐ๋ก ๊ฐ๋ ฅํ ํ์ ์์ฑํฉ๋๋ค"
|
1236 |
+
)
|
1237 |
+
flexibility = gr.Slider(
|
1238 |
+
minimum=0.0, maximum=0.05,
|
1239 |
+
label="๐คธโโ๏ธ ์ ์ฐ์ฑ",
|
1240 |
+
value=0.02,
|
1241 |
+
info="๋์ ํ ์ํํฌ๋ฆญ์ค ๊ตฌ์กฐ๋ก ์ ์ฐํ ์์ง์์ ๊ฐ๋ฅํ๊ฒ ํฉ๋๋ค"
|
1242 |
+
)
|
1243 |
+
|
1244 |
+
with gr.Row():
|
1245 |
+
speed = gr.Slider(
|
1246 |
+
minimum=0.0, maximum=0.20,
|
1247 |
+
label="โก ์คํผ๋",
|
1248 |
+
value=0.1,
|
1249 |
+
info="๋ฃจํ ๊ตฌ์กฐ๋ก ๋น ๋ฅธ ์์ง์์ ๊ตฌํํฉ๋๋ค"
|
1250 |
+
)
|
1251 |
+
defense = gr.Slider(
|
1252 |
+
minimum=-10, maximum=10,
|
1253 |
+
label="๐ก๏ธ ๋ฐฉ์ด๋ ฅ",
|
1254 |
+
value=0,
|
1255 |
+
info="์์: ์์ค ํ๋์ ํนํ, ์์: ์ง์ ํ๋์ ํนํ"
|
1256 |
+
)
|
1257 |
+
|
1258 |
+
# ํ์ด๋ก ํฌ๊ธฐ ์ค์
|
1259 |
+
hero_size = gr.Slider(
|
1260 |
+
minimum=50, maximum=200,
|
1261 |
+
label="๐ ์ปค์คํ
๋จ๋ฐฑ์ง ํฌ๊ธฐ",
|
1262 |
+
value=100,
|
1263 |
+
info="์ ์ฒด์ ์ธ ํฌ๊ธฐ๋ฅผ ๊ฒฐ์ ํฉ๋๋ค"
|
1264 |
+
)
|
1265 |
+
|
1266 |
+
# ํน์ ๋ฅ๋ ฅ ์ค์
|
1267 |
+
with gr.Accordion("๐ ํน์ ๋ฅ๋ ฅ", open=False):
|
1268 |
+
gr.Markdown("""
|
1269 |
+
ํน์ ๋ฅ๋ ฅ์ ์ ํํ๋ฉด ์ปค์คํ
๋จ๋ฐฑ์ง์ง์ ํน๋ณํ ๊ตฌ์กฐ๊ฐ ์ถ๊ฐ๋ฉ๋๋ค.
|
1270 |
+
- ์๊ฐ ํ๋ณต: ๋จ๋ฐฑ์ง ๊ตฌ์กฐ ๋ณต๊ตฌ ๋ฅ๋ ฅ ๊ฐํ
|
1271 |
+
- ์๊ฑฐ๋ฆฌ ๊ณต๊ฒฉ: ํน์ํ ๊ตฌ์กฐ์ ๋์ถ๋ถ ํ์ฑ
|
1272 |
+
- ๋ฐฉ์ด๋ง ์์ฑ: ์์ ์ ์ธ ๋ณดํธ์ธต ๊ตฌ์กฐ ์์ฑ
|
1273 |
+
""")
|
1274 |
+
special_ability = gr.CheckboxGroup(
|
1275 |
+
choices=["์๊ฐ ํ๋ณต", "์๊ฑฐ๋ฆฌ ๊ณต๊ฒฉ", "๋ฐฉ์ด๋ง ์์ฑ"],
|
1276 |
+
label="ํน์ ๋ฅ๋ ฅ ์ ํ"
|
1277 |
+
)
|
1278 |
+
|
1279 |
+
# ์์ฑ ๋ฒํผ
|
1280 |
+
create_btn = gr.Button("๐งฌ ์ปค์คํ
๋จ๋ฐฑ์ง ์์ฑ!", variant="primary", scale=2)
|
1281 |
+
|
1282 |
+
with gr.TabItem("๐งฌ ์ปค์คํ
๋จ๋ฐฑ์ง ์ค๊ณ"):
|
1283 |
+
gr.Markdown("""
|
1284 |
+
### ๐งช ์ปค์คํ
๋จ๋ฐฑ์ง ๊ณ ๊ธ ์ค์
|
1285 |
+
์ ์ ์ ๊ตฌ์กฐ๋ฅผ ๋ ์ธ๋ฐํ๊ฒ ์กฐ์ ํ ์ ์์ต๋๋ค.
|
1286 |
+
""")
|
1287 |
+
|
1288 |
+
seq_opt = gr.Radio(
|
1289 |
+
["์๋ ์ค๊ณ", "์ง์ ์
๋ ฅ"],
|
1290 |
+
label="DNA ์ค๊ณ ๋ฐฉ์",
|
1291 |
+
value="์๋ ์ค๊ณ"
|
1292 |
+
)
|
1293 |
+
|
1294 |
+
sequence = gr.Textbox(
|
1295 |
+
label="๋จ๋ฐฑ์ง ์ํ์ค",
|
1296 |
+
lines=1,
|
1297 |
+
placeholder='์ฌ์ฉ ๊ฐ๋ฅํ ์๋ฏธ๋
ธ์ฐ: A,C,D,E,F,G,H,I,K,L,M,N,P,Q,R,S,T,V,W,Y (X๋ ๋ฌด์์)',
|
1298 |
+
visible=False
|
1299 |
+
)
|
1300 |
+
seq_len = gr.Slider(
|
1301 |
+
minimum=5.0, maximum=250.0,
|
1302 |
+
label="DNA ๊ธธ์ด",
|
1303 |
+
value=100,
|
1304 |
+
visible=True
|
1305 |
+
)
|
1306 |
+
|
1307 |
+
with gr.Accordion(label='๐ฆด ๊ณจ๊ฒฉ ๊ตฌ์กฐ ์ค์ ', open=True):
|
1308 |
+
gr.Markdown("""
|
1309 |
+
์ปค์คํ
๋จ๋ฐฑ์ง ๊ธฐ๋ณธ ๊ณจ๊ฒฉ ๊ตฌ์กฐ๋ฅผ ์ค์ ํฉ๋๋ค.
|
1310 |
+
- ๋์ ํ ๊ตฌ์กฐ: ์ ์ฐํ๊ณ ํ๋ ฅ์๋ ์์ง์
|
1311 |
+
- ๋ณํํ ๊ตฌ์กฐ: ๋จ๋จํ๊ณ ๊ฐ๋ ฅํ ํ
|
1312 |
+
- ๊ณ ๋ฆฌํ ๊ตฌ์กฐ: ๋น ๋ฅด๊ณ ๋ฏผ์ฒฉํ ์์ง์
|
1313 |
+
""")
|
1314 |
+
sec_str_opt = gr.Radio(
|
1315 |
+
["์ฌ๋ผ์ด๋๋ก ์ค์ ", "์ง์ ์
๋ ฅ"],
|
1316 |
+
label="๊ณจ๊ฒฉ ๊ตฌ์กฐ ์ค์ ๋ฐฉ์",
|
1317 |
+
value="์ฌ๋ผ์ด๋๋ก ์ค์ "
|
1318 |
+
)
|
1319 |
+
|
1320 |
+
secondary_structure = gr.Textbox(
|
1321 |
+
label="๊ณจ๊ฒฉ ๊ตฌ์กฐ",
|
1322 |
+
lines=1,
|
1323 |
+
placeholder='H:๋์ ํ, S:๋ณํํ, L:๊ณ ๋ฆฌํ, X:์๋์ค์ ',
|
1324 |
+
visible=False
|
1325 |
+
)
|
1326 |
+
|
1327 |
+
with gr.Column():
|
1328 |
+
helix_bias = gr.Slider(
|
1329 |
+
minimum=0.0, maximum=0.05,
|
1330 |
+
label="๋์ ํ ๊ตฌ์กฐ ๋น์จ",
|
1331 |
+
visible=True
|
1332 |
+
)
|
1333 |
+
strand_bias = gr.Slider(
|
1334 |
+
minimum=0.0, maximum=0.05,
|
1335 |
+
label="๋ณํํ ๊ตฌ์กฐ ๋น์จ",
|
1336 |
+
visible=True
|
1337 |
+
)
|
1338 |
+
loop_bias = gr.Slider(
|
1339 |
+
minimum=0.0, maximum=0.20,
|
1340 |
+
label="๊ณ ๋ฆฌํ ๊ตฌ์กฐ ๋น์จ",
|
1341 |
+
visible=True
|
1342 |
+
)
|
1343 |
+
|
1344 |
+
with gr.Accordion(label='๐งฌ ๋จ๋ฐฑ์ง ๊ตฌ์ฑ ์ค์ ', open=False):
|
1345 |
+
gr.Markdown("""
|
1346 |
+
ํน์ ์๋ฏธ๋
ธ์ฐ์ ๋น์จ์ ์กฐ์ ํ์ฌ ํน์ฑ์ ๊ฐํํ ์ ์์ต๋๋ค.
|
1347 |
+
์์: W0.2,E0.1 (ํธ๋ฆฝํ ํ 20%, ๊ธ๋ฃจํ์ฐ 10%)
|
1348 |
+
""")
|
1349 |
+
with gr.Row():
|
1350 |
+
aa_bias = gr.Textbox(
|
1351 |
+
label="์๋ฏธ๋
ธ์ฐ ๋น์จ",
|
1352 |
+
lines=1,
|
1353 |
+
placeholder='์์: W0.2,E0.1'
|
1354 |
+
)
|
1355 |
+
aa_bias_potential = gr.Textbox(
|
1356 |
+
label="๊ฐํ ์ ๋",
|
1357 |
+
lines=1,
|
1358 |
+
placeholder='1.0-5.0 ์ฌ์ด ๊ฐ ์
๋ ฅ'
|
1359 |
+
)
|
1360 |
+
|
1361 |
+
with gr.Accordion(label='๐ ํ๊ฒฝ ์ ์๋ ฅ ์ค์ ', open=False):
|
1362 |
+
gr.Markdown("""
|
1363 |
+
ํ๊ฒฝ ์ ์๋ ฅ์ ์กฐ์ ํฉ๋๋ค.
|
1364 |
+
์์: ์์ค ํ๋์ ํนํ, ์์: ์ง์ ํ๋์ ํนํ
|
1365 |
+
""")
|
1366 |
+
with gr.Row():
|
1367 |
+
hydrophobic_target_score = gr.Textbox(
|
1368 |
+
label="ํ๊ฒฝ ์ ์ ์ ์",
|
1369 |
+
lines=1,
|
1370 |
+
placeholder='์์: -5 (์์ค ํ๋์ ํนํ)'
|
1371 |
+
)
|
1372 |
+
hydrophobic_potential = gr.Textbox(
|
1373 |
+
label="์ ์๋ ฅ ๊ฐํ ์ ๋",
|
1374 |
+
lines=1,
|
1375 |
+
placeholder='1.0-2.0 ์ฌ์ด ๊ฐ ์
๋ ฅ'
|
1376 |
+
)
|
1377 |
+
|
1378 |
+
with gr.Accordion(label='โ๏ธ ๊ณ ๊ธ ์ค์ ', open=False):
|
1379 |
+
gr.Markdown("""
|
1380 |
+
DNA ์์ฑ ๊ณผ์ ์ ์ธ๋ถ ๋งค๊ฐ๋ณ์๋ฅผ ์กฐ์ ํฉ๋๋ค.
|
1381 |
+
""")
|
1382 |
+
with gr.Row():
|
1383 |
+
num_steps = gr.Textbox(
|
1384 |
+
label="์์ฑ ๋จ๊ณ",
|
1385 |
+
lines=1,
|
1386 |
+
placeholder='25 ์ดํ ๊ถ์ฅ'
|
1387 |
+
)
|
1388 |
+
noise = gr.Dropdown(
|
1389 |
+
['normal','gmm2 [-1,1]','gmm3 [-1,0,1]'],
|
1390 |
+
label='๋
ธ์ด์ฆ ํ์
',
|
1391 |
+
value='normal'
|
1392 |
+
)
|
1393 |
+
|
1394 |
+
design_btn = gr.Button("๐งฌ ๋จ๋ฐฑ์ง ์ค๊ณ ์์ฑ!", variant="primary", scale=2)
|
1395 |
+
|
1396 |
+
with gr.TabItem("๐งช ์ปค์คํ
๋จ๋ฐฑ์ง ๊ฐํ"):
|
1397 |
+
gr.Markdown("""
|
1398 |
+
### โก ๊ธฐ์กด ์ปค์คํ
๋จ๋ฐฑ์ง ํ์ฉ
|
1399 |
+
๊ธฐ์กด ๋จ๋ฐฑ์ง ์ผ๋ถ๋ฅผ ์๋ก์ด ์ปค์คํ
์๊ฒ ์ด์ํฉ๋๋ค.
|
1400 |
+
""")
|
1401 |
+
|
1402 |
+
gr.Markdown("๊ณต๊ฐ๋ ์ปค์คํ
๋จ๋ฐฑ์ง ๋ฐ์ดํฐ๋ฒ ์ด์ค์์ ์ฝ๋๋ฅผ ์ฐพ์ ์ ์์ต๋๋ค")
|
1403 |
+
pdb_id_code = gr.Textbox(
|
1404 |
+
label="์ปค์คํ
๋จ๋ฐฑ์ง ์ฝ๋",
|
1405 |
+
lines=1,
|
1406 |
+
placeholder='๊ธฐ์กด ์ปค์คํ
๋จ๋ฐฑ์ง ์ฝ๋๋ฅผ ์
๋ ฅํ์ธ์ (์: 1DPX)'
|
1407 |
+
)
|
1408 |
+
|
1409 |
+
gr.Markdown("์ด์ํ๊ณ ์ถ์ ๋จ๋ฐฑ์ง ์์ญ์ ์ ํํ๊ณ ์๋ก์ด ๋จ๋ฐฑ์ง์ ์ถ๊ฐํ ์ ์์ต๋๋ค")
|
1410 |
+
contigs = gr.Textbox(
|
1411 |
+
label="์ด์ํ ๋จ๋ฐฑ์ง ์๏ฟฝ๏ฟฝ",
|
1412 |
+
lines=1,
|
1413 |
+
placeholder='์์: 15,A3-10,20-30'
|
1414 |
+
)
|
1415 |
+
|
1416 |
+
with gr.Row():
|
1417 |
+
seq_mask = gr.Textbox(
|
1418 |
+
label='๋ฅ๋ ฅ ์ฌ์ค๊ณ',
|
1419 |
+
lines=1,
|
1420 |
+
placeholder='์ ํํ ์์ญ์ ๋ฅ๋ ฅ์ ์๋กญ๊ฒ ๋์์ธ'
|
1421 |
+
)
|
1422 |
+
str_mask = gr.Textbox(
|
1423 |
+
label='๊ตฌ์กฐ ์ฌ์ค๊ณ',
|
1424 |
+
lines=1,
|
1425 |
+
placeholder='์ ํํ ์์ญ์ ๊ตฌ์กฐ๋ฅผ ์๋กญ๊ฒ ๋์์ธ'
|
1426 |
+
)
|
1427 |
+
|
1428 |
+
preview_viewer = gr.HTML()
|
1429 |
+
rewrite_pdb = gr.File(label='์ปค์คํ
๋จ๋ฐฑ์ง ํ์ผ')
|
1430 |
+
preview_btn = gr.Button("๐ ๋ฏธ๋ฆฌ๋ณด๊ธฐ", variant="secondary")
|
1431 |
+
enhance_btn = gr.Button("โก ๊ฐํ๋ ์ปค์คํ
๋จ๋ฐฑ์ง ์์ฑ!", variant="primary", scale=2)
|
1432 |
+
|
1433 |
+
with gr.TabItem("๐ ์ปค์คํ
๋จ๋ฐฑ์ง ์กฑ๋ณด"):
|
1434 |
+
gr.Markdown("""
|
1435 |
+
### ๐ฐ ์๋ํ ์ปค์คํ
๋จ๋ฐฑ์ง ๊ฐ๋ฌธ์ ์ ์ฐ
|
1436 |
+
๊ฐ๋ ฅํ ํน์ฑ์ ๊ณ์นํ์ฌ ์๋ก์ด ์ปค์คํ
๋จ๋ฐฑ์ง์ ๋ง๋ญ๋๋ค.
|
1437 |
+
""")
|
1438 |
+
|
1439 |
+
with gr.Row():
|
1440 |
+
with gr.Column():
|
1441 |
+
gr.Markdown("์ปค์คํ
๋จ๋ฐฑ์ง ์ ๋ณด๊ฐ ๋ด๊ธด ํ์ผ์ ์
๋ก๋ํ์ธ์")
|
1442 |
+
fasta_msa = gr.File(label='๊ฐ๋ฌธ DNA ๋ฐ์ดํฐ')
|
1443 |
+
with gr.Column():
|
1444 |
+
gr.Markdown("์ด๋ฏธ ๋ถ์๋ ๊ฐ๋ฌธ ํน์ฑ ๋ฐ์ดํฐ๊ฐ ์๋ค๋ฉด ์
๋ก๋ํ์ธ์")
|
1445 |
+
input_pssm = gr.File(label='๊ฐ๋ฌธ ํน์ฑ ๋ฐ์ดํฐ')
|
1446 |
+
|
1447 |
+
pssm = gr.File(label='๋ถ์๋ ๊ฐ๋ฌธ ํน์ฑ')
|
1448 |
+
pssm_view = gr.Plot(label='๊ฐ๋ฌธ ํน์ฑ ๋ถ์ ๊ฒฐ๊ณผ')
|
1449 |
+
pssm_gen_btn = gr.Button("โจ ๊ฐ๋ฌธ ํน์ฑ ๋ถ์", variant="secondary")
|
1450 |
+
inherit_btn = gr.Button("๐ ๊ฐ๋ฌธ์ ํ ๊ณ์น!", variant="primary", scale=2)
|
1451 |
+
|
1452 |
+
# ์ค๋ฅธ์ชฝ ์ด: ๊ฒฐ๊ณผ ํ์
|
1453 |
+
with gr.Column(scale=1):
|
1454 |
+
gr.Markdown("## ๐ฆธโโ๏ธ ์ปค์คํ
๋จ๋ฐฑ์ง ํ๋กํ")
|
1455 |
+
hero_stats = gr.Plot(label="๋ฅ๋ ฅ์น ๋ถ์")
|
1456 |
+
hero_description = gr.Textbox(label="์ปค์คํ
๋จ๋ฐฑ์ง ํน์ฑ", lines=3)
|
1457 |
+
|
1458 |
+
gr.Markdown("## ๐งฌ ์ปค์คํ
๋จ๋ฐฑ์ง ๋ถ์ ๊ฒฐ๊ณผ")
|
1459 |
+
gr.Markdown("#### โก ์ปค์คํ
๋จ๋ฐฑ์ง ์์ ์ฑ ์ ์")
|
1460 |
+
plddt_plot = gr.Plot(label='์์ ์ฑ ๋ถ์')
|
1461 |
+
gr.Markdown("#### ๐ ์ปค์คํ
๋จ๋ฐฑ์ง ์ํ์ค")
|
1462 |
+
output_seq = gr.Textbox(label="์ปค์คํ
๋จ๋ฐฑ์ง ์์ด")
|
1463 |
+
gr.Markdown("#### ๐พ ์ปค์คํ
๋จ๋ฐฑ์ง ๋ฐ์ดํฐ")
|
1464 |
+
output_pdb = gr.File(label="์ปค์คํ
๋จ๋ฐฑ์ง ํ์ผ")
|
1465 |
+
gr.Markdown("#### ๐ฌ ์ปค์คํ
๋จ๋ฐฑ์ง ๊ตฌ์กฐ")
|
1466 |
+
output_viewer = gr.HTML()
|
1467 |
+
|
1468 |
+
# ์ด๋ฒคํธ ์ฐ๊ฒฐ
|
1469 |
+
# ์ฑ๋ด ์ด๋ฒคํธ
|
1470 |
+
msg.submit(process_chat, [msg, chatbot], [chatbot])
|
1471 |
+
clear.click(lambda: None, None, chatbot, queue=False)
|
1472 |
+
|
1473 |
+
seq_opt.change(
|
1474 |
+
fn=toggle_seq_input,
|
1475 |
+
inputs=[seq_opt],
|
1476 |
+
outputs=[seq_len, sequence],
|
1477 |
+
queue=False
|
1478 |
+
)
|
1479 |
+
|
1480 |
+
|
1481 |
+
|
1482 |
+
sec_str_opt.change(
|
1483 |
+
fn=toggle_secondary_structure,
|
1484 |
+
inputs=[sec_str_opt],
|
1485 |
+
outputs=[helix_bias, strand_bias, loop_bias, secondary_structure],
|
1486 |
+
queue=False
|
1487 |
+
)
|
1488 |
+
|
1489 |
+
preview_btn.click(
|
1490 |
+
get_motif_preview,
|
1491 |
+
inputs=[pdb_id_code, contigs],
|
1492 |
+
outputs=[preview_viewer, rewrite_pdb]
|
1493 |
+
)
|
1494 |
+
|
1495 |
+
pssm_gen_btn.click(
|
1496 |
+
get_pssm,
|
1497 |
+
inputs=[fasta_msa, input_pssm],
|
1498 |
+
outputs=[pssm_view, pssm]
|
1499 |
+
)
|
1500 |
+
|
1501 |
+
# ์ฑ๋ด ๊ธฐ๋ฐ ๋จ๋ฐฑ์ง ์์ฑ ๊ฒฐ๊ณผ ์
๋ฐ์ดํธ
|
1502 |
+
def update_protein_display(chat_response):
|
1503 |
+
if "์์ฑ๋ ๋จ๋ฐฑ์ง ๋ถ์" in chat_response:
|
1504 |
+
params = extract_parameters_from_chat(chat_response)
|
1505 |
+
result = generate_protein(params)
|
1506 |
+
return {
|
1507 |
+
hero_stats: create_radar_chart(calculate_hero_stats(params)),
|
1508 |
+
hero_description: chat_response,
|
1509 |
+
output_seq: result[0],
|
1510 |
+
output_pdb: result[1],
|
1511 |
+
output_viewer: display_pdb(result[1]),
|
1512 |
+
plddt_plot: result[3]
|
1513 |
+
}
|
1514 |
+
return None
|
1515 |
+
|
1516 |
+
# ๊ฐ ์์ฑ ๋ฒํผ ์ด๋ฒคํธ ์ฐ๊ฒฐ
|
1517 |
+
for btn in [create_btn, design_btn, enhance_btn, inherit_btn]:
|
1518 |
+
btn.click(
|
1519 |
+
combined_generation,
|
1520 |
+
inputs=[
|
1521 |
+
hero_name, strength, flexibility, speed, defense, hero_size, special_ability,
|
1522 |
+
sequence, seq_len, helix_bias, strand_bias, loop_bias,
|
1523 |
+
secondary_structure, aa_bias, aa_bias_potential,
|
1524 |
+
num_steps, noise, hydrophobic_target_score, hydrophobic_potential,
|
1525 |
+
contigs, pssm, seq_mask, str_mask, rewrite_pdb
|
1526 |
+
],
|
1527 |
+
outputs=[
|
1528 |
+
hero_stats,
|
1529 |
+
hero_description,
|
1530 |
+
output_seq,
|
1531 |
+
output_pdb,
|
1532 |
+
output_viewer,
|
1533 |
+
plddt_plot
|
1534 |
+
]
|
1535 |
+
)
|
1536 |
+
|
1537 |
+
# ์ด๋ฒคํธ ํธ๋ค๋ฌ ์ฐ๊ฒฐ
|
1538 |
+
msg.submit(
|
1539 |
+
fn=process_chat_and_generate,
|
1540 |
+
inputs=[msg, chatbot],
|
1541 |
+
outputs=[
|
1542 |
+
chatbot,
|
1543 |
+
hero_stats,
|
1544 |
+
hero_description,
|
1545 |
+
output_seq,
|
1546 |
+
output_pdb,
|
1547 |
+
output_viewer,
|
1548 |
+
plddt_plot
|
1549 |
+
]
|
1550 |
+
)
|
1551 |
+
|
1552 |
+
submit_btn.click(
|
1553 |
+
fn=process_chat_and_generate,
|
1554 |
+
inputs=[msg, chatbot],
|
1555 |
+
outputs=[
|
1556 |
+
chatbot,
|
1557 |
+
hero_stats,
|
1558 |
+
hero_description,
|
1559 |
+
output_seq,
|
1560 |
+
output_pdb,
|
1561 |
+
output_viewer,
|
1562 |
+
plddt_plot
|
1563 |
+
]
|
1564 |
+
)
|
1565 |
+
|
1566 |
+
# ์ฑํ
๋ด์ฉ ์ง์ฐ๊ธฐ
|
1567 |
+
clear.click(
|
1568 |
+
lambda: (None, None, None, None, None, None, None),
|
1569 |
+
None,
|
1570 |
+
[chatbot, hero_stats, hero_description, output_seq, output_pdb, output_viewer, plddt_plot],
|
1571 |
+
queue=False
|
1572 |
+
)
|
1573 |
+
|
1574 |
+
# ์ฑ๋ด ์๋ต์ ๋ฐ๋ฅธ ๊ฒฐ๊ณผ ์
๋ฐ์ดํธ
|
1575 |
+
msg.submit(
|
1576 |
+
update_protein_display,
|
1577 |
+
inputs=[chatbot],
|
1578 |
+
outputs=[hero_stats, hero_description, output_seq, output_pdb, output_viewer, plddt_plot]
|
1579 |
+
)
|
1580 |
+
|
1581 |
+
|
1582 |
+
submit_btn.click(respond,
|
1583 |
+
[msg, chatbot, system_message, max_tokens, temperature, top_p],
|
1584 |
+
[chatbot])
|
1585 |
+
msg.submit(respond,
|
1586 |
+
[msg, chatbot, system_message, max_tokens, temperature, top_p],
|
1587 |
+
[chatbot])
|
1588 |
+
clear.click(lambda: None, None, chatbot, queue=False)
|
1589 |
+
|
1590 |
+
|
1591 |
+
# ์ด๋ฒคํธ ํธ๋ค๋ฌ ์ฐ๊ฒฐ
|
1592 |
+
msg.submit(
|
1593 |
+
fn=process_chat_and_generate,
|
1594 |
+
inputs=[msg, chatbot],
|
1595 |
+
outputs=[
|
1596 |
+
chatbot,
|
1597 |
+
hero_stats,
|
1598 |
+
hero_description,
|
1599 |
+
output_seq,
|
1600 |
+
output_pdb,
|
1601 |
+
output_viewer,
|
1602 |
+
plddt_plot
|
1603 |
+
],
|
1604 |
+
show_progress=True
|
1605 |
+
)
|
1606 |
+
|
1607 |
+
submit_btn.click(
|
1608 |
+
fn=process_chat_and_generate,
|
1609 |
+
inputs=[msg, chatbot],
|
1610 |
+
outputs=[
|
1611 |
+
chatbot,
|
1612 |
+
hero_stats,
|
1613 |
+
hero_description,
|
1614 |
+
output_seq,
|
1615 |
+
output_pdb,
|
1616 |
+
output_viewer,
|
1617 |
+
plddt_plot
|
1618 |
+
],
|
1619 |
+
show_progress=True
|
1620 |
+
)
|
1621 |
+
|
1622 |
+
|
1623 |
+
# ์คํ
|
1624 |
+
demo.queue()
|
1625 |
+
demo.launch(debug=True)
|