aiqcamp commited on
Commit
6f38a8f
ยท
verified ยท
1 Parent(s): 99e133c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +76 -32
app.py CHANGED
@@ -845,6 +845,69 @@ def combined_generation(name, strength, flexibility, speed, defense, size, abili
845
  )
846
 
847
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
848
  def process_chat_and_generate(message, history):
849
  try:
850
  # 1. ํ”„๋กฌํ”„ํŠธ ๋ถ„์„ ๋ฐ ํŒŒ๋ผ๋ฏธํ„ฐ ์„ค์ •
@@ -876,7 +939,15 @@ def process_chat_and_generate(message, history):
876
  # 3. ์ƒ์„ฑ ๊ฒฐ๊ณผ ๊ฐ€์ ธ์˜ค๊ธฐ
877
  output_seq, output_pdb, structure_view, plddt_plot = next(generator)
878
 
879
- # 4. ์„ค๋ช… ์ƒ์„ฑ
 
 
 
 
 
 
 
 
880
  explanation = f"""
881
  ์š”์ฒญํ•˜์‹  ๊ธฐ๋Šฅ์— ๋งž๋Š” ๋‹จ๋ฐฑ์งˆ์„ ์ƒ์„ฑํ–ˆ์Šต๋‹ˆ๋‹ค:
882
 
@@ -891,16 +962,16 @@ def process_chat_and_generate(message, history):
891
  - ์†Œ์ˆ˜์„ฑ ์ ์ˆ˜: {params['hydrophobic_target_score']}
892
  """
893
 
894
- # 5. ์ฑ—๋ด‡ ํžˆ์Šคํ† ๋ฆฌ ์—…๋ฐ์ดํŠธ
895
  new_history = history + [
896
  {"role": "user", "content": message},
897
  {"role": "assistant", "content": explanation}
898
  ]
899
 
900
- # 6. ๋ชจ๋“  ๊ฒฐ๊ณผ ๋ฐ˜ํ™˜
901
  return (
902
  new_history, # ์ฑ—๋ด‡ ํžˆ์Šคํ† ๋ฆฌ
903
- create_radar_chart(calculate_hero_stats(params)), # ๋Šฅ๋ ฅ์น˜ ์ฐจํŠธ
904
  explanation, # ์„ค๋ช…
905
  output_seq, # ๋‹จ๋ฐฑ์งˆ ์„œ์—ด
906
  output_pdb, # PDB ํŒŒ์ผ
@@ -975,34 +1046,7 @@ def calculate_similarity(keywords, entry):
975
  print("Entry:", entry)
976
  return 0
977
 
978
- def extract_parameters_from_chat(chat_response):
979
- """์ฑ—๋ด‡ ์‘๋‹ต์—์„œ ํŒŒ๋ผ๋ฏธํ„ฐ ์ถ”์ถœ"""
980
- try:
981
- params = {
982
- 'sequence_length': 100,
983
- 'helix_bias': 0.02,
984
- 'strand_bias': 0.02,
985
- 'loop_bias': 0.1,
986
- 'hydrophobic_target_score': 0
987
- }
988
-
989
- # ์‘๋‹ต ํ…์ŠคํŠธ์—์„œ ๊ฐ’ ์ถ”์ถœ
990
- if "๊ธธ์ด:" in chat_response:
991
- length_match = re.search(r'๊ธธ์ด: (\d+)', chat_response)
992
- if length_match:
993
- params['sequence_length'] = int(length_match.group(1))
994
-
995
- if "์•ŒํŒŒ ํ—ฌ๋ฆญ์Šค ๋น„์œจ:" in chat_response:
996
- helix_match = re.search(r'์•ŒํŒŒ ํ—ฌ๋ฆญ์Šค ๋น„์œจ: ([\d.]+)', chat_response)
997
- if helix_match:
998
- params['helix_bias'] = float(helix_match.group(1)) / 100
999
-
1000
- # ๋‚˜๋จธ์ง€ ํŒŒ๋ผ๋ฏธํ„ฐ๋„ ์œ ์‚ฌํ•˜๊ฒŒ ์ถ”์ถœ
1001
-
1002
- return params
1003
- except Exception as e:
1004
- print(f"ํŒŒ๋ผ๋ฏธํ„ฐ ์ถ”์ถœ ์ค‘ ์˜ค๋ฅ˜: {str(e)}")
1005
- return None
1006
 
1007
  def download_checkpoint_files():
1008
  """ํ•„์š”ํ•œ ์ฒดํฌํฌ์ธํŠธ ํŒŒ์ผ ๋‹ค์šด๋กœ๋“œ"""
 
845
  )
846
 
847
 
848
+ def extract_parameters_from_chat(chat_response):
849
+ """์ฑ—๋ด‡ ์‘๋‹ต์—์„œ ํŒŒ๋ผ๋ฏธํ„ฐ ์ถ”์ถœ"""
850
+ try:
851
+ params = {
852
+ 'sequence_length': 100,
853
+ 'helix_bias': 0.02,
854
+ 'strand_bias': 0.02,
855
+ 'loop_bias': 0.1,
856
+ 'hydrophobic_target_score': 0
857
+ }
858
+
859
+ # ์‘๋‹ต ํ…์ŠคํŠธ์—์„œ ๊ฐ’ ์ถ”์ถœ
860
+ if "๊ธธ์ด:" in chat_response:
861
+ length_match = re.search(r'๊ธธ์ด: (\d+)', chat_response)
862
+ if length_match:
863
+ params['sequence_length'] = int(length_match.group(1))
864
+
865
+ if "์•ŒํŒŒ ํ—ฌ๋ฆญ์Šค ๋น„์œจ:" in chat_response:
866
+ helix_match = re.search(r'์•ŒํŒŒ ํ—ฌ๋ฆญ์Šค ๋น„์œจ: ([\d.]+)', chat_response)
867
+ if helix_match:
868
+ params['helix_bias'] = float(helix_match.group(1)) / 100
869
+
870
+ if "๋ฒ ํƒ€ ์‹œํŠธ ๋น„์œจ:" in chat_response:
871
+ strand_match = re.search(r'๋ฒ ํƒ€ ์‹œํŠธ ๋น„์œจ: ([\d.]+)', chat_response)
872
+ if strand_match:
873
+ params['strand_bias'] = float(strand_match.group(1)) / 100
874
+
875
+ if "๋ฃจํ”„ ๊ตฌ์กฐ ๋น„์œจ:" in chat_response:
876
+ loop_match = re.search(r'๋ฃจํ”„ ๊ตฌ์กฐ ๋น„์œจ: ([\d.]+)', chat_response)
877
+ if loop_match:
878
+ params['loop_bias'] = float(loop_match.group(1)) / 100
879
+
880
+ if "์†Œ์ˆ˜์„ฑ ์ ์ˆ˜:" in chat_response:
881
+ hydro_match = re.search(r'์†Œ์ˆ˜์„ฑ ์ ์ˆ˜: ([-\d.]+)', chat_response)
882
+ if hydro_match:
883
+ params['hydrophobic_target_score'] = float(hydro_match.group(1))
884
+
885
+ return params
886
+ except Exception as e:
887
+ print(f"ํŒŒ๋ผ๋ฏธํ„ฐ ์ถ”์ถœ ์ค‘ ์˜ค๋ฅ˜: {str(e)}")
888
+ return None
889
+
890
+ def update_protein_display(chat_response):
891
+ if "์ƒ์„ฑ๋œ ๋‹จ๋ฐฑ์งˆ ๋ถ„์„" in chat_response:
892
+ params = extract_parameters_from_chat(chat_response)
893
+ if params:
894
+ result = generate_protein(params)
895
+ stats = calculate_hero_stats(
896
+ helix_bias=params['helix_bias'],
897
+ strand_bias=params['strand_bias'],
898
+ loop_bias=params['loop_bias'],
899
+ hydrophobic_score=params['hydrophobic_target_score']
900
+ )
901
+ return {
902
+ hero_stats: create_radar_chart(stats),
903
+ hero_description: chat_response,
904
+ output_seq: result[0],
905
+ output_pdb: result[1],
906
+ output_viewer: display_pdb(result[1]),
907
+ plddt_plot: result[3]
908
+ }
909
+ return None
910
+
911
  def process_chat_and_generate(message, history):
912
  try:
913
  # 1. ํ”„๋กฌํ”„ํŠธ ๋ถ„์„ ๋ฐ ํŒŒ๋ผ๋ฏธํ„ฐ ์„ค์ •
 
939
  # 3. ์ƒ์„ฑ ๊ฒฐ๊ณผ ๊ฐ€์ ธ์˜ค๊ธฐ
940
  output_seq, output_pdb, structure_view, plddt_plot = next(generator)
941
 
942
+ # 4. ํžˆ์–ด๋กœ ๋Šฅ๋ ฅ์น˜ ๊ณ„์‚ฐ
943
+ stats = calculate_hero_stats(
944
+ helix_bias=params['helix_bias'],
945
+ strand_bias=params['strand_bias'],
946
+ loop_bias=params['loop_bias'],
947
+ hydrophobic_score=params['hydrophobic_target_score']
948
+ )
949
+
950
+ # 5. ์„ค๋ช… ์ƒ์„ฑ
951
  explanation = f"""
952
  ์š”์ฒญํ•˜์‹  ๊ธฐ๋Šฅ์— ๋งž๋Š” ๋‹จ๋ฐฑ์งˆ์„ ์ƒ์„ฑํ–ˆ์Šต๋‹ˆ๋‹ค:
953
 
 
962
  - ์†Œ์ˆ˜์„ฑ ์ ์ˆ˜: {params['hydrophobic_target_score']}
963
  """
964
 
965
+ # 6. ์ฑ—๋ด‡ ํžˆ์Šคํ† ๋ฆฌ ์—…๋ฐ์ดํŠธ
966
  new_history = history + [
967
  {"role": "user", "content": message},
968
  {"role": "assistant", "content": explanation}
969
  ]
970
 
971
+ # 7. ๋ชจ๋“  ๊ฒฐ๊ณผ ๋ฐ˜ํ™˜
972
  return (
973
  new_history, # ์ฑ—๋ด‡ ํžˆ์Šคํ† ๋ฆฌ
974
+ create_radar_chart(stats), # ๋Šฅ๋ ฅ์น˜ ์ฐจํŠธ
975
  explanation, # ์„ค๋ช…
976
  output_seq, # ๋‹จ๋ฐฑ์งˆ ์„œ์—ด
977
  output_pdb, # PDB ํŒŒ์ผ
 
1046
  print("Entry:", entry)
1047
  return 0
1048
 
1049
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1050
 
1051
  def download_checkpoint_files():
1052
  """ํ•„์š”ํ•œ ์ฒดํฌํฌ์ธํŠธ ํŒŒ์ผ ๋‹ค์šด๋กœ๋“œ"""