aiqcamp commited on
Commit
1dab7bb
ยท
verified ยท
1 Parent(s): 3a56ec4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +106 -73
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
- # 2. ๋‹จ๋ฐฑ์งˆ ์ƒ์„ฑ
 
 
 
 
 
 
 
 
 
 
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
- # 3. ๋ชจ๋“  ๋‹จ๊ณ„์˜ ๊ฒฐ๊ณผ ์ˆ˜์ง‘
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": f"๋‹จ๋ฐฑ์งˆ ์ƒ์„ฑ ์ค‘... {len(plddt_data)}๋‹จ๊ณ„ ์™„๋ฃŒ"}
978
  ],
979
- create_radar_chart(stats),
980
- f"๋‹จ๋ฐฑ์งˆ ์ƒ์„ฑ ์ง„ํ–‰ ์ค‘... {len(plddt_data)}๋‹จ๊ณ„ ์™„๋ฃŒ",
 
 
 
 
 
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
- final_explanation = f"""
997
- ๋‹จ๋ฐฑ์งˆ ์„ค๊ณ„๊ฐ€ ์™„๋ฃŒ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.
998
 
999
- [๋ถ„์„ ๊ฒฐ๊ณผ]
1000
- {analysis}
 
 
 
 
1001
 
1002
- [๊ตฌ์กฐ์  ํŠน์ง•]
1003
- - ๊ธธ์ด: {params['sequence_length']} ์•„๋ฏธ๋…ธ์‚ฐ
1004
- - ์•ŒํŒŒ ํ—ฌ๋ฆญ์Šค ๋น„์œจ: {params['helix_bias']*100:.1f}%
1005
- - ๋ฒ ํƒ€ ์‹œํŠธ ๋น„์œจ: {params['strand_bias']*100:.1f}%
1006
- - ๋ฃจํ”„ ๊ตฌ์กฐ ๋น„์œจ: {params['loop_bias']*100:.1f}%
1007
- - ์†Œ์ˆ˜์„ฑ ์ ์ˆ˜: {params['hydrophobic_target_score']}
1008
 
1009
- [์ƒ์„ฑ ๊ณผ์ •]
1010
- - ์ด {len(plddt_data)}๋‹จ๊ณ„์˜ ์ตœ์ ํ™” ์ˆ˜ํ–‰
1011
- - ์ตœ์ข… ์•ˆ์ •์„ฑ ์ ์ˆ˜: {np.mean(plddt_data) if plddt_data else 0:.2f}
1012
- - ์ฐธ์กฐ๋œ ์œ ์‚ฌ ๊ตฌ์กฐ: {len(similar_structures)}๊ฐœ
1013
 
1014
- [๊ธฐ๋Šฅ์  ํŠน์„ฑ]
1015
- - ์ฃผ์š” ํ™œ์„ฑ ๋ถ€์œ„: {analyze_active_sites(output_seq)}
1016
- - ์˜ˆ์ƒ๋˜๋Š” ์ƒํ˜ธ์ž‘์šฉ: {predict_interactions(params)}
1017
- - ์•ˆ์ •์„ฑ ํ‰๊ฐ€: {evaluate_stability(plddt_data)}
 
 
 
 
 
 
 
 
 
 
 
 
 
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": f"์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ–ˆ์Šต๋‹ˆ๋‹ค: {str(e)}"}
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()