jonathang commited on
Commit
9232135
1 Parent(s): 06e7238

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -5
app.py CHANGED
@@ -1,6 +1,7 @@
1
  import gradio as gr
2
  import os
3
  import gc
 
4
 
5
  import numpy as np
6
  import pandas as pd
@@ -97,11 +98,18 @@ def get_model():
97
 
98
 
99
  model = get_model()
100
-
101
- def greet(seq):
102
- processed_seq = Sequence.prepare(seq)
103
- raw_prediction = model.predict(processed_seq)
104
- return f"Input is {seq}.\nProcessed input is:\n{processed_seq}\n\nModel makes prediction:\n{raw_prediction}"
 
 
 
 
 
 
 
105
 
106
  iface = gr.Interface(fn=greet, inputs="text", outputs="text")
107
  iface.launch()
 
1
  import gradio as gr
2
  import os
3
  import gc
4
+ import json
5
 
6
  import numpy as np
7
  import pandas as pd
 
98
 
99
 
100
  model = get_model()
101
+ mappings_path = cached_download(hf_hub_url("jonathang/Protein_Family_CNN", 'prot_mappings.json'))
102
+ with open(mappings_path) as f:
103
+ prot_mappings = json.load(f)
104
+
105
+ def greet(Amino_Acid_Sequence):
106
+ processed_seq = Sequence.prepare(Amino_Acid_Sequence)
107
+ raw_prediction = model.predict(processed_seq)[0]
108
+ idx = raw_prediction.argmax()
109
+ fam_asc = prot_mappings['id2fam_asc'][idx]
110
+ fam_id = prot_mappings['fam_asc2fam_id'][fam_asc]
111
+ gc.collect()
112
+ return f"Input is {Amino_Acid_Sequence}.\nProcessed input is:\n{processed_seq}\n\nModel makes prediction:\n{raw_prediction}\nWhich gives index {idx}.\nWhich maps to family ascension {fam_asc} and ID {fam_id}"
113
 
114
  iface = gr.Interface(fn=greet, inputs="text", outputs="text")
115
  iface.launch()