Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -931,72 +931,42 @@ def evaluate_stability(plddt_data):
|
|
| 931 |
|
| 932 |
def process_chat_and_generate(message, history):
|
| 933 |
try:
|
| 934 |
-
# 1. ์ด๊ธฐ ์๋ต ์์ฑ
|
| 935 |
-
|
| 936 |
-
|
| 937 |
-
|
| 938 |
-
|
| 939 |
-
|
| 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 |
-
|
| 951 |
-
|
| 952 |
-
|
| 953 |
-
|
| 954 |
-
|
| 955 |
-
|
| 956 |
-
|
| 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 |
-
|
| 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'],
|
|
@@ -1004,54 +974,47 @@ def process_chat_and_generate(message, history):
|
|
| 1004 |
float(params['hydrophobic_target_score'])
|
| 1005 |
)),
|
| 1006 |
progress_msg,
|
| 1007 |
-
result[0],
|
| 1008 |
-
result[1],
|
| 1009 |
-
result[2],
|
| 1010 |
-
result[3]
|
| 1011 |
)
|
| 1012 |
|
| 1013 |
-
# 6. ์ต์ข
๊ฒฐ๊ณผ ๋ฐ ์ค๋ช
|
| 1014 |
-
|
| 1015 |
-
|
| 1016 |
-
|
| 1017 |
-
final_explanation = f"""
|
| 1018 |
-
๋จ๋ฐฑ์ง ์ค๊ณ๊ฐ ์๋ฃ๋์์ต๋๋ค.
|
| 1019 |
|
| 1020 |
-
|
| 1021 |
-
|
| 1022 |
|
| 1023 |
-
|
| 1024 |
-
|
| 1025 |
-
|
| 1026 |
-
|
| 1027 |
-
|
| 1028 |
-
|
| 1029 |
|
| 1030 |
-
|
| 1031 |
-
|
| 1032 |
-
|
| 1033 |
-
|
| 1034 |
|
| 1035 |
-
|
| 1036 |
-
|
| 1037 |
|
| 1038 |
-
|
| 1039 |
-
|
| 1040 |
-
|
| 1041 |
-
|
| 1042 |
-
|
| 1043 |
-
|
| 1044 |
-
|
| 1045 |
-
|
| 1046 |
-
|
| 1047 |
-
|
| 1048 |
-
|
| 1049 |
-
|
| 1050 |
-
|
| 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)}")
|
|
@@ -1563,7 +1526,7 @@ with gr.Blocks(theme='ParityError/Interstellar') as demo:
|
|
| 1563 |
]
|
| 1564 |
)
|
| 1565 |
|
| 1566 |
-
|
| 1567 |
clear.click(
|
| 1568 |
lambda: (None, None, None, None, None, None, None),
|
| 1569 |
None,
|
|
@@ -1571,6 +1534,7 @@ with gr.Blocks(theme='ParityError/Interstellar') as demo:
|
|
| 1571 |
queue=False
|
| 1572 |
)
|
| 1573 |
|
|
|
|
| 1574 |
# ์ฑ๋ด ์๋ต์ ๋ฐ๋ฅธ ๊ฒฐ๊ณผ ์
๋ฐ์ดํธ
|
| 1575 |
msg.submit(
|
| 1576 |
update_protein_display,
|
|
|
|
| 931 |
|
| 932 |
def process_chat_and_generate(message, history):
|
| 933 |
try:
|
| 934 |
+
# 1. ์ด๊ธฐ ์๋ต ์์ฑ (์ด์ ๋ํ ๊ธฐ๋ก ์ ์ง)
|
| 935 |
+
current_history = history + [
|
| 936 |
+
{"role": "user", "content": message},
|
| 937 |
+
{"role": "assistant", "content": "๋จ๋ฐฑ์ง ์ค๊ณ๋ฅผ ์์ํฉ๋๋ค. ์ ์๋ง ๊ธฐ๋ค๋ ค์ฃผ์ธ์..."}
|
| 938 |
+
]
|
| 939 |
+
yield (current_history, None, None, None, None, None, None)
|
|
|
|
|
|
|
|
|
|
| 940 |
|
| 941 |
# 2. ํ๋กฌํํธ ๋ถ์
|
| 942 |
analysis = analyze_prompt(message)
|
| 943 |
similar_structures = search_protein_data(analysis, ds)
|
| 944 |
params = extract_parameters(analysis, similar_structures)
|
| 945 |
|
| 946 |
+
# 3. ๋ถ์ ๊ฒฐ๊ณผ ์ถ๊ฐ (์ด์ ๋ฉ์์ง ์ ์ง)
|
| 947 |
+
current_history = current_history[:-1] + [
|
| 948 |
+
{"role": "assistant", "content": f"""
|
| 949 |
+
๋ถ์ ๊ฒฐ๊ณผ:
|
| 950 |
+
{analysis}
|
| 951 |
+
|
| 952 |
+
๋จ๋ฐฑ์ง ๊ตฌ์กฐ ์์ฑ์ ์์ํฉ๋๋ค...
|
| 953 |
+
"""}
|
| 954 |
+
]
|
| 955 |
+
yield (current_history, None, None, None, None, None, None)
|
| 956 |
|
| 957 |
# 4. ๋จ๋ฐฑ์ง ์์ฑ
|
| 958 |
+
generator = protein_diffusion_model(...) # ๊ธฐ์กด ํ๋ผ๋ฏธํฐ ์ ์ง
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 959 |
|
| 960 |
+
# 5. ์์ฑ ๊ณผ์ ์ถ์ (์ด์ ๋ฉ์์ง๋ค ์ ์ง)
|
|
|
|
|
|
|
| 961 |
step = 0
|
|
|
|
| 962 |
for result in generator:
|
| 963 |
step += 1
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 964 |
progress_msg = f"๋จ๋ฐฑ์ง ์์ฑ ์ค... {step}/25 ๋จ๊ณ ์๋ฃ"
|
| 965 |
+
current_history = current_history[:-1] + [
|
| 966 |
+
{"role": "assistant", "content": progress_msg}
|
| 967 |
+
]
|
| 968 |
yield (
|
| 969 |
+
current_history,
|
|
|
|
|
|
|
|
|
|
| 970 |
create_radar_chart(calculate_hero_stats(
|
| 971 |
params['helix_bias'],
|
| 972 |
params['strand_bias'],
|
|
|
|
| 974 |
float(params['hydrophobic_target_score'])
|
| 975 |
)),
|
| 976 |
progress_msg,
|
| 977 |
+
result[0],
|
| 978 |
+
result[1],
|
| 979 |
+
result[2],
|
| 980 |
+
result[3]
|
| 981 |
)
|
| 982 |
|
| 983 |
+
# 6. ์ต์ข
๊ฒฐ๊ณผ ๋ฐ ์ค๋ช
์ถ๊ฐ (๋ชจ๋ ์ด์ ๋ฉ์์ง ์ ์ง)
|
| 984 |
+
final_explanation = f"""
|
| 985 |
+
๋จ๋ฐฑ์ง ์ค๊ณ๊ฐ ์๋ฃ๋์์ต๋๋ค.
|
|
|
|
|
|
|
|
|
|
| 986 |
|
| 987 |
+
[๋ถ์ ๊ฒฐ๊ณผ]
|
| 988 |
+
{analysis}
|
| 989 |
|
| 990 |
+
[๊ตฌ์กฐ์ ํน์ง]
|
| 991 |
+
- ๊ธธ์ด: {params['sequence_length']} ์๋ฏธ๋
ธ์ฐ
|
| 992 |
+
- ์ํ ํฌ๋ฆญ์ค ๋น์จ: {params['helix_bias']*100:.1f}%
|
| 993 |
+
- ๋ฒ ํ ์ํธ ๋น์จ: {params['strand_bias']*100:.1f}%
|
| 994 |
+
- ๋ฃจํ ๊ตฌ์กฐ ๋น์จ: {params['loop_bias']*100:.1f}%
|
| 995 |
+
- ์์์ฑ ์ ์: {params['hydrophobic_target_score']}
|
| 996 |
|
| 997 |
+
[์์ฑ ๊ณผ์ ]
|
| 998 |
+
- ์ด {step}๋จ๊ณ์ ์ต์ ํ ์๋ฃ
|
| 999 |
+
- ์ต์ข
์์ ์ฑ ์ ์: {np.mean(plddt_data) if plddt_data else 0:.2f}
|
| 1000 |
+
- ์ฐธ์กฐ๋ ์ ์ฌ ๊ตฌ์กฐ: {len(similar_structures)}๊ฐ
|
| 1001 |
|
| 1002 |
+
3D ๊ตฌ์กฐ์ ์์ธ ๋ถ์ ๊ฒฐ๊ณผ๋ฅผ ํ์ธํ์ค ์ ์์ต๋๋ค.
|
| 1003 |
+
"""
|
| 1004 |
|
| 1005 |
+
final_history = current_history + [
|
| 1006 |
+
{"role": "assistant", "content": final_explanation}
|
| 1007 |
+
]
|
| 1008 |
+
|
| 1009 |
+
return (
|
| 1010 |
+
final_history, # ๋ชจ๋ ๋ํ ๊ธฐ๋ก ์ ์ง
|
| 1011 |
+
create_radar_chart(stats),
|
| 1012 |
+
final_explanation,
|
| 1013 |
+
output_seq,
|
| 1014 |
+
output_pdb,
|
| 1015 |
+
structure_view,
|
| 1016 |
+
plddt_plot
|
| 1017 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1018 |
|
| 1019 |
except Exception as e:
|
| 1020 |
print(f"Error in process_chat_and_generate: {str(e)}")
|
|
|
|
| 1526 |
]
|
| 1527 |
)
|
| 1528 |
|
| 1529 |
+
# ์ฑํ
๋ด์ฉ ์ง์ฐ๊ธฐ ๋ฒํผ
|
| 1530 |
clear.click(
|
| 1531 |
lambda: (None, None, None, None, None, None, None),
|
| 1532 |
None,
|
|
|
|
| 1534 |
queue=False
|
| 1535 |
)
|
| 1536 |
|
| 1537 |
+
|
| 1538 |
# ์ฑ๋ด ์๋ต์ ๋ฐ๋ฅธ ๊ฒฐ๊ณผ ์
๋ฐ์ดํธ
|
| 1539 |
msg.submit(
|
| 1540 |
update_protein_display,
|