aiqcamp commited on
Commit
fc6decc
ยท
verified ยท
1 Parent(s): 10f5f24

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +58 -94
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
- 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'],
@@ -1004,54 +974,47 @@ def process_chat_and_generate(message, history):
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)}")
@@ -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,