Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
@@ -188,9 +188,8 @@ def search_protein_data(analysis, dataset):
|
|
188 |
print(f"Error processing entry: {str(e)}")
|
189 |
continue
|
190 |
|
191 |
-
# ๊ฒฐ๊ณผ ์ ๋ ฌ ๋ฐ ๋ฐํ
|
192 |
-
scored_entries
|
193 |
-
return scored_entries[:3]
|
194 |
|
195 |
except Exception as e:
|
196 |
print(f"๋ฐ์ดํฐ ๊ฒ์ ์ค ์ค๋ฅ: {str(e)}")
|
@@ -944,8 +943,25 @@ def process_chat_and_generate(message, history):
|
|
944 |
|
945 |
# 2. ํ๋กฌํํธ ๋ถ์
|
946 |
analysis = analyze_prompt(message)
|
|
|
|
|
|
|
|
|
|
|
|
|
947 |
similar_structures = search_protein_data(analysis, ds)
|
|
|
|
|
|
|
|
|
|
|
|
|
948 |
params = extract_parameters(analysis, similar_structures)
|
|
|
|
|
|
|
|
|
|
|
949 |
|
950 |
# 3. ๋ถ์ ๊ฒฐ๊ณผ ์ถ๊ฐ (์ด์ ๋ฉ์์ง ์ ์ง)
|
951 |
current_history = current_history[:-1] + [
|
@@ -959,71 +975,115 @@ def process_chat_and_generate(message, history):
|
|
959 |
yield (current_history, None, None, None, None, None, None)
|
960 |
|
961 |
# 4. ๋จ๋ฐฑ์ง ์์ฑ
|
962 |
-
|
963 |
-
|
964 |
-
|
965 |
-
|
966 |
-
|
967 |
-
|
968 |
-
|
969 |
-
|
970 |
-
|
971 |
-
|
972 |
-
|
973 |
-
|
974 |
-
|
975 |
-
|
976 |
-
|
977 |
-
|
978 |
-
|
979 |
-
|
980 |
-
|
981 |
-
result[0],
|
982 |
-
result[1],
|
983 |
-
result[2],
|
984 |
-
result[3]
|
985 |
)
|
986 |
|
987 |
-
|
988 |
-
|
989 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
990 |
|
991 |
-
|
992 |
-
|
993 |
|
994 |
-
|
995 |
-
|
996 |
-
|
997 |
-
|
998 |
-
|
999 |
-
- ์์์ฑ ์ ์: {params['hydrophobic_target_score']}
|
1000 |
|
1001 |
-
|
1002 |
-
|
1003 |
-
- ์ต์ข
์์ ์ฑ ์ ์: {np.mean(plddt_data) if plddt_data else 0:.2f}
|
1004 |
-
- ์ฐธ์กฐ๋ ์ ์ฌ ๊ตฌ์กฐ: {len(similar_structures)}๊ฐ
|
1005 |
|
1006 |
-
|
1007 |
-
|
|
|
|
|
|
|
|
|
1008 |
|
1009 |
-
|
1010 |
-
{
|
1011 |
-
|
|
|
1012 |
|
1013 |
-
|
1014 |
-
|
1015 |
-
|
1016 |
-
|
1017 |
-
|
1018 |
-
|
1019 |
-
|
1020 |
-
|
1021 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1022 |
|
1023 |
except Exception as e:
|
|
|
1024 |
print(f"Error in process_chat_and_generate: {str(e)}")
|
1025 |
traceback.print_exc()
|
1026 |
-
error_msg = f"์ค๋ฅ๊ฐ ๋ฐ์ํ์ต๋๋ค: {str(e)}"
|
1027 |
return (
|
1028 |
history + [
|
1029 |
{"role": "user", "content": message},
|
@@ -1032,10 +1092,6 @@ def process_chat_and_generate(message, history):
|
|
1032 |
None, None, None, None, None, None
|
1033 |
)
|
1034 |
|
1035 |
-
# ํ์ํ ๋ชจ๋ ์ถ๊ฐ
|
1036 |
-
import json
|
1037 |
-
from Bio import SeqIO, Align
|
1038 |
-
from Bio.Seq import Seq
|
1039 |
|
1040 |
# ์์ ๋ถ๋ถ์ ์ถ๊ฐ
|
1041 |
def extract_keywords(analysis):
|
@@ -1066,9 +1122,10 @@ def calculate_similarity(keywords, entry):
|
|
1066 |
"""ํค์๋์ ๋ฐ์ดํฐ์
ํญ๋ชฉ ๊ฐ์ ์ ์ฌ๋ ๊ณ์ฐ"""
|
1067 |
try:
|
1068 |
score = 0
|
1069 |
-
if not
|
1070 |
return 0
|
1071 |
|
|
|
1072 |
sequence = entry.get('sequence', '').lower()
|
1073 |
description = entry.get('description', '')
|
1074 |
|
@@ -1090,8 +1147,13 @@ def calculate_similarity(keywords, entry):
|
|
1090 |
print(f"์ ์ฌ๋ ๊ณ์ฐ ์ค ์ค๋ฅ: {str(e)}")
|
1091 |
return 0
|
1092 |
|
1093 |
-
#
|
1094 |
plddt_data = []
|
|
|
|
|
|
|
|
|
|
|
1095 |
|
1096 |
# ์์ ํ๋กฌํํธ ์ฒ๋ฆฌ ํจ์ ์์
|
1097 |
def use_example(example):
|
@@ -1665,4 +1727,4 @@ with gr.Blocks(theme='ParityError/Interstellar') as demo:
|
|
1665 |
|
1666 |
# ์คํ
|
1667 |
demo.queue()
|
1668 |
-
demo.launch(debug=True)
|
|
|
188 |
print(f"Error processing entry: {str(e)}")
|
189 |
continue
|
190 |
|
191 |
+
# ๊ฒฐ๊ณผ ์ ๋ ฌ ๋ฐ ๋ฐํ (key ํจ์ ์ฌ์ฉ)
|
192 |
+
return sorted(scored_entries, key=lambda x: x[0], reverse=True)[:3]
|
|
|
193 |
|
194 |
except Exception as e:
|
195 |
print(f"๋ฐ์ดํฐ ๊ฒ์ ์ค ์ค๋ฅ: {str(e)}")
|
|
|
943 |
|
944 |
# 2. ํ๋กฌํํธ ๋ถ์
|
945 |
analysis = analyze_prompt(message)
|
946 |
+
if not analysis:
|
947 |
+
return history + [
|
948 |
+
{"role": "user", "content": message},
|
949 |
+
{"role": "assistant", "content": "์์ฒญ ๋ถ์์ ์คํจํ์ต๋๋ค."}
|
950 |
+
], None, None, None, None, None, None
|
951 |
+
|
952 |
similar_structures = search_protein_data(analysis, ds)
|
953 |
+
if not similar_structures:
|
954 |
+
return history + [
|
955 |
+
{"role": "user", "content": message},
|
956 |
+
{"role": "assistant", "content": "์ ํฉํ ์ฐธ์กฐ ๊ตฌ์กฐ๋ฅผ ์ฐพ์ง ๋ชปํ์ต๋๋ค."}
|
957 |
+
], None, None, None, None, None, None
|
958 |
+
|
959 |
params = extract_parameters(analysis, similar_structures)
|
960 |
+
if not params:
|
961 |
+
return history + [
|
962 |
+
{"role": "user", "content": message},
|
963 |
+
{"role": "assistant", "content": "ํ๋ผ๋ฏธํฐ ์ค์ ์ ์คํจํ์ต๋๋ค."}
|
964 |
+
], None, None, None, None, None, None
|
965 |
|
966 |
# 3. ๋ถ์ ๊ฒฐ๊ณผ ์ถ๊ฐ (์ด์ ๋ฉ์์ง ์ ์ง)
|
967 |
current_history = current_history[:-1] + [
|
|
|
975 |
yield (current_history, None, None, None, None, None, None)
|
976 |
|
977 |
# 4. ๋จ๋ฐฑ์ง ์์ฑ
|
978 |
+
try:
|
979 |
+
generator = protein_diffusion_model(
|
980 |
+
sequence=None,
|
981 |
+
seq_len=params['sequence_length'],
|
982 |
+
helix_bias=params['helix_bias'],
|
983 |
+
strand_bias=params['strand_bias'],
|
984 |
+
loop_bias=params['loop_bias'],
|
985 |
+
secondary_structure=None,
|
986 |
+
aa_bias=None,
|
987 |
+
aa_bias_potential=None,
|
988 |
+
num_steps="25",
|
989 |
+
noise="normal",
|
990 |
+
hydrophobic_target_score=str(params['hydrophobic_target_score']),
|
991 |
+
hydrophobic_potential="2",
|
992 |
+
contigs=None,
|
993 |
+
pssm=None,
|
994 |
+
seq_mask=None,
|
995 |
+
str_mask=None,
|
996 |
+
rewrite_pdb=None
|
|
|
|
|
|
|
|
|
997 |
)
|
998 |
|
999 |
+
# 5. ์์ฑ ๊ณผ์ ์ถ์ (์ด์ ๋ฉ์์ง๋ค ์ ์ง)
|
1000 |
+
step = 0
|
1001 |
+
final_result = None
|
1002 |
+
for result in generator:
|
1003 |
+
step += 1
|
1004 |
+
final_result = result
|
1005 |
+
progress_msg = f"๋จ๋ฐฑ์ง ์์ฑ ์ค... {step}/25 ๋จ๊ณ ์๋ฃ"
|
1006 |
+
current_history = current_history[:-1] + [
|
1007 |
+
{"role": "assistant", "content": progress_msg}
|
1008 |
+
]
|
1009 |
+
yield (
|
1010 |
+
current_history,
|
1011 |
+
create_radar_chart(calculate_hero_stats(
|
1012 |
+
params['helix_bias'],
|
1013 |
+
params['strand_bias'],
|
1014 |
+
params['loop_bias'],
|
1015 |
+
float(params['hydrophobic_target_score'])
|
1016 |
+
)),
|
1017 |
+
progress_msg,
|
1018 |
+
result[0], # output_seq
|
1019 |
+
result[1], # output_pdb
|
1020 |
+
result[2], # structure_view
|
1021 |
+
result[3] # plddt_plot
|
1022 |
+
)
|
1023 |
|
1024 |
+
if final_result is None:
|
1025 |
+
raise Exception("์์ฑ ๊ฒฐ๊ณผ๊ฐ ์์ต๋๋ค")
|
1026 |
|
1027 |
+
# 6. ์ต์ข
๊ฒฐ๊ณผ ๋ฐ ์ค๋ช
์ถ๊ฐ
|
1028 |
+
output_seq, output_pdb, structure_view, plddt_plot = final_result
|
1029 |
+
|
1030 |
+
final_explanation = f"""
|
1031 |
+
๋จ๋ฐฑ์ง ์ค๊ณ๊ฐ ์๋ฃ๋์์ต๋๋ค.
|
|
|
1032 |
|
1033 |
+
[๋ถ์ ๊ฒฐ๊ณผ]
|
1034 |
+
{analysis}
|
|
|
|
|
1035 |
|
1036 |
+
[๊ตฌ์กฐ์ ํน์ง]
|
1037 |
+
- ๊ธธ์ด: {params['sequence_length']} ์๋ฏธ๋
ธ์ฐ
|
1038 |
+
- ์ํ ํฌ๋ฆญ์ค ๋น์จ: {params['helix_bias']*100:.1f}%
|
1039 |
+
- ๋ฒ ํ ์ํธ ๋น์จ: {params['strand_bias']*100:.1f}%
|
1040 |
+
- ๋ฃจํ ๊ตฌ์กฐ ๋น์จ: {params['loop_bias']*100:.1f}%
|
1041 |
+
- ์์์ฑ ์ ์: {params['hydrophobic_target_score']}
|
1042 |
|
1043 |
+
[์์ฑ ๊ณผ์ ]
|
1044 |
+
- ์ด {step}๋จ๊ณ์ ์ต์ ํ ์๋ฃ
|
1045 |
+
- ์ต์ข
์์ ์ฑ ์ ์: {np.mean(plddt_data) if plddt_data else 0:.2f}
|
1046 |
+
- ์ฐธ์กฐ๋ ์ ์ฌ ๊ตฌ์กฐ: {len(similar_structures)}๊ฐ
|
1047 |
|
1048 |
+
3D ๊ตฌ์กฐ์ ์์ธ ๋ถ์ ๊ฒฐ๊ณผ๋ฅผ ํ์ธํ์ค ์ ์์ต๋๋ค.
|
1049 |
+
"""
|
1050 |
+
|
1051 |
+
final_history = current_history + [
|
1052 |
+
{"role": "assistant", "content": final_explanation}
|
1053 |
+
]
|
1054 |
+
|
1055 |
+
stats = calculate_hero_stats(
|
1056 |
+
params['helix_bias'],
|
1057 |
+
params['strand_bias'],
|
1058 |
+
params['loop_bias'],
|
1059 |
+
float(params['hydrophobic_target_score'])
|
1060 |
+
)
|
1061 |
+
|
1062 |
+
return (
|
1063 |
+
final_history,
|
1064 |
+
create_radar_chart(stats),
|
1065 |
+
final_explanation,
|
1066 |
+
output_seq,
|
1067 |
+
output_pdb,
|
1068 |
+
structure_view,
|
1069 |
+
plddt_plot
|
1070 |
+
)
|
1071 |
+
|
1072 |
+
except Exception as e:
|
1073 |
+
error_msg = f"๋จ๋ฐฑ์ง ์์ฑ ์ค ์ค๋ฅ๊ฐ ๋ฐ์ํ์ต๋๋ค: {str(e)}"
|
1074 |
+
print(error_msg)
|
1075 |
+
traceback.print_exc()
|
1076 |
+
return (
|
1077 |
+
current_history + [
|
1078 |
+
{"role": "assistant", "content": error_msg}
|
1079 |
+
],
|
1080 |
+
None, None, None, None, None, None
|
1081 |
+
)
|
1082 |
|
1083 |
except Exception as e:
|
1084 |
+
error_msg = f"์ฒ๋ฆฌ ์ค ์ค๋ฅ๊ฐ ๋ฐ์ํ์ต๋๋ค: {str(e)}"
|
1085 |
print(f"Error in process_chat_and_generate: {str(e)}")
|
1086 |
traceback.print_exc()
|
|
|
1087 |
return (
|
1088 |
history + [
|
1089 |
{"role": "user", "content": message},
|
|
|
1092 |
None, None, None, None, None, None
|
1093 |
)
|
1094 |
|
|
|
|
|
|
|
|
|
1095 |
|
1096 |
# ์์ ๋ถ๋ถ์ ์ถ๊ฐ
|
1097 |
def extract_keywords(analysis):
|
|
|
1122 |
"""ํค์๋์ ๋ฐ์ดํฐ์
ํญ๋ชฉ ๊ฐ์ ์ ์ฌ๋ ๊ณ์ฐ"""
|
1123 |
try:
|
1124 |
score = 0
|
1125 |
+
if not isinstance(entry, dict):
|
1126 |
return 0
|
1127 |
|
1128 |
+
# ์์ ํ ์ ๊ทผ์ ์ํ get ๋ฉ์๋ ์ฌ์ฉ
|
1129 |
sequence = entry.get('sequence', '').lower()
|
1130 |
description = entry.get('description', '')
|
1131 |
|
|
|
1147 |
print(f"์ ์ฌ๋ ๊ณ์ฐ ์ค ์ค๋ฅ: {str(e)}")
|
1148 |
return 0
|
1149 |
|
1150 |
+
# ์ ์ญ ๋ณ์ ์ ์
|
1151 |
plddt_data = []
|
1152 |
+
stats = {} # ๋ฅ๋ ฅ์น ์ ์ฅ์ฉ
|
1153 |
+
output_seq = None
|
1154 |
+
output_pdb = None
|
1155 |
+
structure_view = None
|
1156 |
+
plddt_plot = None
|
1157 |
|
1158 |
# ์์ ํ๋กฌํํธ ์ฒ๋ฆฌ ํจ์ ์์
|
1159 |
def use_example(example):
|
|
|
1727 |
|
1728 |
# ์คํ
|
1729 |
demo.queue()
|
1730 |
+
demo.launch(debug=True, share=True)
|