matanninio commited on
Commit
93d0d1a
1 Parent(s): 72dbfd7
Files changed (3) hide show
  1. __init__.py +0 -0
  2. demo_framework.py +107 -0
  3. new_app.py +1 -98
__init__.py ADDED
File without changes
demo_framework.py ADDED
@@ -0,0 +1,107 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from fuse.data.tokenizers.modular_tokenizer.op import ModularTokenizerOp
3
+ from mammal.examples.dti_bindingdb_kd.task import DtiBindingdbKdTask
4
+ from mammal.keys import *
5
+ from mammal.model import Mammal
6
+ from abc import ABC, abstractmethod
7
+
8
+
9
+
10
+
11
+
12
+ class MammalObjectBroker():
13
+ def __init__(self, model_path: str, name:str= None, task_list: list[str]=None) -> None:
14
+ self.model_path = model_path
15
+ if name is None:
16
+ name = model_path
17
+ self.name = name
18
+
19
+ if task_list is not None:
20
+ self.tasks=task_list
21
+ else:
22
+ self.task = []
23
+ self._model = None
24
+ self._tokenizer_op = None
25
+
26
+
27
+ @property
28
+ def model(self)-> Mammal:
29
+ if self._model is None:
30
+ self._model = Mammal.from_pretrained(self.model_path)
31
+ self._model.eval()
32
+ return self._model
33
+
34
+ @property
35
+ def tokenizer_op(self):
36
+ if self._tokenizer_op is None:
37
+ self._tokenizer_op = ModularTokenizerOp.from_pretrained(self.model_path)
38
+ return self._tokenizer_op
39
+
40
+
41
+
42
+
43
+ class MammalTask(ABC):
44
+ def __init__(self, name:str) -> None:
45
+ self.name = name
46
+ self.description = None
47
+ self._demo = None
48
+
49
+ # @abstractmethod
50
+ # def _generate_prompt(self, **kwargs) -> str:
51
+ # """Formatting prompt to match pre-training syntax
52
+
53
+ # Args:
54
+ # prot1 (_type_): _description_
55
+ # prot2 (_type_): _description_
56
+
57
+ # Raises:
58
+ # No: _description_
59
+ # """
60
+ # raise NotImplementedError()
61
+
62
+ @abstractmethod
63
+ def crate_sample_dict(self,sample_inputs: dict, model_holder:MammalObjectBroker) -> dict:
64
+ """Formatting prompt to match pre-training syntax
65
+
66
+ Args:
67
+ prompt (str): _description_
68
+
69
+ Returns:
70
+ dict: sample_dict for feeding into model
71
+ """
72
+ raise NotImplementedError()
73
+
74
+ # @abstractmethod
75
+ def run_model(self, sample_dict, model:Mammal):
76
+ raise NotImplementedError()
77
+
78
+ def create_demo(self, model_name_widget: gr.component) -> gr.Group:
79
+ """create an gradio demo group
80
+
81
+ Args:
82
+ model_name_widgit (gr.Component): widget holding the model name to use. This is needed to create
83
+ gradio actions with the current model name as an input
84
+
85
+
86
+ Raises:
87
+ NotImplementedError: _description_
88
+ """
89
+ raise NotImplementedError()
90
+
91
+
92
+
93
+ def demo(self,model_name_widgit:gr.component=None):
94
+ if self._demo is None:
95
+ model_name_widget:gr.component
96
+ self._demo = self.create_demo(model_name_widget=model_name_widgit)
97
+ return self._demo
98
+
99
+ @abstractmethod
100
+ def decode_output(self,batch_dict, model:Mammal):
101
+ raise NotImplementedError()
102
+
103
+ #self._setup()
104
+
105
+ # def _setup(self):
106
+ # pass
107
+
new_app.py CHANGED
@@ -4,105 +4,8 @@ from fuse.data.tokenizers.modular_tokenizer.op import ModularTokenizerOp
4
  from mammal.examples.dti_bindingdb_kd.task import DtiBindingdbKdTask
5
  from mammal.keys import *
6
  from mammal.model import Mammal
7
- from abc import ABC, abstractmethod
8
- class MammalObjectBroker():
9
- def __init__(self, model_path: str, name:str= None, task_list: list[str]=None) -> None:
10
- self.model_path = model_path
11
- if name is None:
12
- name = model_path
13
- self.name = name
14
-
15
- if task_list is not None:
16
- self.tasks=task_list
17
- else:
18
- self.task = []
19
- self._model = None
20
- self._tokenizer_op = None
21
-
22
-
23
- @property
24
- def model(self)-> Mammal:
25
- if self._model is None:
26
- self._model = Mammal.from_pretrained(self.model_path)
27
- self._model.eval()
28
- return self._model
29
-
30
- @property
31
- def tokenizer_op(self):
32
- if self._tokenizer_op is None:
33
- self._tokenizer_op = ModularTokenizerOp.from_pretrained(self.model_path)
34
- return self._tokenizer_op
35
-
36
-
37
-
38
-
39
-
40
- class MammalTask(ABC):
41
- def __init__(self, name:str) -> None:
42
- self.name = name
43
- self.description = None
44
- self._demo = None
45
-
46
- # @abstractmethod
47
- # def _generate_prompt(self, **kwargs) -> str:
48
- # """Formatting prompt to match pre-training syntax
49
-
50
- # Args:
51
- # prot1 (_type_): _description_
52
- # prot2 (_type_): _description_
53
-
54
- # Raises:
55
- # No: _description_
56
- # """
57
- # raise NotImplementedError()
58
-
59
- @abstractmethod
60
- def crate_sample_dict(self,sample_inputs: dict, model_holder:MammalObjectBroker) -> dict:
61
- """Formatting prompt to match pre-training syntax
62
-
63
- Args:
64
- prompt (str): _description_
65
-
66
- Returns:
67
- dict: sample_dict for feeding into model
68
- """
69
- raise NotImplementedError()
70
-
71
- # @abstractmethod
72
- def run_model(self, sample_dict, model:Mammal):
73
- raise NotImplementedError()
74
-
75
- def create_demo(self, model_name_widget: gr.component) -> gr.Group:
76
- """create an gradio demo group
77
-
78
- Args:
79
- model_name_widgit (gr.Component): widget holding the model name to use. This is needed to create
80
- gradio actions with the current model name as an input
81
-
82
-
83
- Raises:
84
- NotImplementedError: _description_
85
- """
86
- raise NotImplementedError()
87
-
88
-
89
-
90
- def demo(self,model_name_widgit:gr.component=None):
91
- if self._demo is None:
92
- model_name_widget:gr.component
93
- self._demo = self.create_demo(model_name_widget=model_name_widgit)
94
- return self._demo
95
-
96
- @abstractmethod
97
- def decode_output(self,batch_dict, model:Mammal):
98
- raise NotImplementedError()
99
-
100
- #self._setup()
101
-
102
- # def _setup(self):
103
- # pass
104
-
105
 
 
106
 
107
  all_tasks = dict()
108
  all_models= dict()
 
4
  from mammal.examples.dti_bindingdb_kd.task import DtiBindingdbKdTask
5
  from mammal.keys import *
6
  from mammal.model import Mammal
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7
 
8
+ from demo_framework import MammalObjectBroker, MammalTask
9
 
10
  all_tasks = dict()
11
  all_models= dict()