Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -909,12 +909,30 @@ def update_protein_display(chat_response):
|
|
| 909 |
}
|
| 910 |
return None
|
| 911 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 912 |
def process_chat_and_generate(message, history):
|
| 913 |
try:
|
| 914 |
-
# ์ด๊ธฐ ์๋ต ์์ฑ
|
| 915 |
initial_response = "๋จ๋ฐฑ์ง ์ค๊ณ๋ฅผ ์์ํฉ๋๋ค. ์ ์๋ง ๊ธฐ๋ค๋ ค์ฃผ์ธ์..."
|
| 916 |
-
|
| 917 |
-
# ์ด๊ธฐ ์๋ต ํ์
|
| 918 |
yield (
|
| 919 |
history + [
|
| 920 |
{"role": "user", "content": message},
|
|
@@ -923,13 +941,22 @@ def process_chat_and_generate(message, history):
|
|
| 923 |
None, None, None, None, None, None
|
| 924 |
)
|
| 925 |
|
| 926 |
-
|
| 927 |
-
# 1. ํ๋กฌํํธ ๋ถ์ ๋ฐ ํ๋ผ๋ฏธํฐ ์ค์
|
| 928 |
analysis = analyze_prompt(message)
|
| 929 |
similar_structures = search_protein_data(analysis, ds)
|
| 930 |
params = extract_parameters(analysis, similar_structures)
|
| 931 |
-
|
| 932 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 933 |
generator = protein_diffusion_model(
|
| 934 |
sequence=None,
|
| 935 |
seq_len=params['sequence_length'],
|
|
@@ -949,102 +976,95 @@ def process_chat_and_generate(message, history):
|
|
| 949 |
str_mask=None,
|
| 950 |
rewrite_pdb=None
|
| 951 |
)
|
| 952 |
-
|
| 953 |
-
#
|
| 954 |
final_result = None
|
| 955 |
plddt_data = []
|
| 956 |
-
|
| 957 |
-
|
| 958 |
-
stats = calculate_hero_stats(
|
| 959 |
-
helix_bias=params['helix_bias'],
|
| 960 |
-
strand_bias=params['strand_bias'],
|
| 961 |
-
loop_bias=params['loop_bias'],
|
| 962 |
-
hydrophobic_score=float(params['hydrophobic_target_score'])
|
| 963 |
-
)
|
| 964 |
-
|
| 965 |
for result in generator:
|
|
|
|
| 966 |
final_result = result
|
| 967 |
if result[3]: # plddt_plot์ด ์กด์ฌํ๋ ๊ฒฝ์ฐ
|
| 968 |
ax = result[3].gca()
|
| 969 |
if ax.lines:
|
| 970 |
line = ax.lines[0]
|
| 971 |
plddt_data = line.get_ydata().tolist()
|
| 972 |
-
|
| 973 |
-
|
| 974 |
yield (
|
| 975 |
history + [
|
| 976 |
{"role": "user", "content": message},
|
| 977 |
-
{"role": "assistant", "content":
|
| 978 |
],
|
| 979 |
-
create_radar_chart(
|
| 980 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 981 |
result[0], # output_seq
|
| 982 |
result[1], # output_pdb
|
| 983 |
result[2], # structure_view
|
| 984 |
result[3] # plddt_plot
|
| 985 |
)
|
| 986 |
-
|
| 987 |
-
if final_result is None:
|
| 988 |
-
raise Exception("์์ฑ ๊ฒฐ๊ณผ๊ฐ ์์ต๋๋ค")
|
| 989 |
-
|
| 990 |
-
output_seq, output_pdb, structure_view, plddt_plot = final_result
|
| 991 |
-
|
| 992 |
|
| 993 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 994 |
|
| 995 |
-
|
| 996 |
-
|
| 997 |
-
๋จ๋ฐฑ์ง ์ค๊ณ๊ฐ ์๋ฃ๋์์ต๋๋ค.
|
| 998 |
|
| 999 |
-
|
| 1000 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1001 |
|
| 1002 |
-
|
| 1003 |
-
|
| 1004 |
-
|
| 1005 |
-
|
| 1006 |
-
- ๋ฃจํ ๊ตฌ์กฐ ๋น์จ: {params['loop_bias']*100:.1f}%
|
| 1007 |
-
- ์์์ฑ ์ ์: {params['hydrophobic_target_score']}
|
| 1008 |
|
| 1009 |
-
|
| 1010 |
-
|
| 1011 |
-
- ์ต์ข
์์ ์ฑ ์ ์: {np.mean(plddt_data) if plddt_data else 0:.2f}
|
| 1012 |
-
- ์ฐธ์กฐ๋ ์ ์ฌ ๊ตฌ์กฐ: {len(similar_structures)}๊ฐ
|
| 1013 |
|
| 1014 |
-
|
| 1015 |
-
|
| 1016 |
-
|
| 1017 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1018 |
|
| 1019 |
-
3D ๊ตฌ์กฐ์ ์์ธ ๋ถ์ ๊ฒฐ๊ณผ๋ฅผ ํ์ธํ์ค ์ ์์ต๋๋ค.
|
| 1020 |
-
"""
|
| 1021 |
-
|
| 1022 |
-
return (
|
| 1023 |
-
history + [
|
| 1024 |
-
{"role": "user", "content": message},
|
| 1025 |
-
{"role": "assistant", "content": final_explanation}
|
| 1026 |
-
],
|
| 1027 |
-
create_radar_chart(stats),
|
| 1028 |
-
final_explanation,
|
| 1029 |
-
output_seq,
|
| 1030 |
-
output_pdb,
|
| 1031 |
-
structure_view,
|
| 1032 |
-
plddt_plot
|
| 1033 |
-
)
|
| 1034 |
-
|
| 1035 |
except Exception as e:
|
| 1036 |
print(f"Error in process_chat_and_generate: {str(e)}")
|
| 1037 |
traceback.print_exc()
|
|
|
|
| 1038 |
return (
|
| 1039 |
history + [
|
| 1040 |
{"role": "user", "content": message},
|
| 1041 |
-
{"role": "assistant", "content":
|
| 1042 |
],
|
| 1043 |
None, None, None, None, None, None
|
| 1044 |
)
|
| 1045 |
|
| 1046 |
-
|
| 1047 |
-
|
| 1048 |
def extract_keywords(analysis):
|
| 1049 |
"""๋ถ์ ํ
์คํธ์์ ํค์๋ ์ถ์ถ"""
|
| 1050 |
try:
|
|
@@ -1567,7 +1587,8 @@ with gr.Blocks(theme='ParityError/Interstellar') as demo:
|
|
| 1567 |
[chatbot])
|
| 1568 |
clear.click(lambda: None, None, chatbot, queue=False)
|
| 1569 |
|
| 1570 |
-
|
|
|
|
| 1571 |
msg.submit(
|
| 1572 |
fn=process_chat_and_generate,
|
| 1573 |
inputs=[msg, chatbot],
|
|
@@ -1581,11 +1602,23 @@ with gr.Blocks(theme='ParityError/Interstellar') as demo:
|
|
| 1581 |
plddt_plot
|
| 1582 |
],
|
| 1583 |
show_progress=True
|
| 1584 |
-
).then(
|
| 1585 |
-
lambda: None, # ์งํ ์ํ ์ด๊ธฐํ
|
| 1586 |
-
None,
|
| 1587 |
-
None
|
| 1588 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1589 |
|
| 1590 |
# ์คํ
|
| 1591 |
demo.queue()
|
|
|
|
| 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},
|
|
|
|
| 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'],
|
|
|
|
| 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:
|
|
|
|
| 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],
|
|
|
|
| 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()
|