isThisYouLLM commited on
Commit
1774d37
·
verified ·
1 Parent(s): d4b1deb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -28
app.py CHANGED
@@ -104,62 +104,55 @@ def adapt_model(model:object, dim:int=1024) -> object:
104
 
105
 
106
 
107
- def main():
108
- parser = argparse.ArgumentParser()
109
- parser.add_argument('--model_name', type=str, default="Salesforce/codet5p-770m")
110
- parser.add_argument('--path_checkpoint', type=str, default="checkpoint.bin")
111
- args = parser.parse_args()
112
 
113
 
114
- model_name = args.model_name
115
- checkpoint = args.path_checkpoint
116
 
117
- DEVICE = "cpu"
 
 
 
118
 
119
 
120
 
121
 
122
- #load tokenizer
123
- tokenizer = load_tokenizer(model_name)
124
- print("tokenizer loaded!")
125
 
126
 
127
 
128
 
129
 
130
  #loading model and tokenizer for functional translation
131
- model = load_model(model_name)
132
 
133
  #adding classification head to the model
134
- model = adapt_model(model, dim=model.shared.embedding_dim)
135
 
136
 
137
 
138
 
139
 
140
 
141
- selected = option_menu(
142
  menu_title="Choose your model",
143
  options=["Multilingual_multiprovenance"],
144
  default_index=0,
145
  orientation="horizontal",
146
  )
147
 
148
- if selected=="Multilingual_standard":
149
- model.load_state_dict(torch.load(checkpoint,map_location='cpu'))
150
- model = model.eval()
151
- st.title("Human-AI stylometer - Multilingual_standard")
152
- text = st.text_area("insert your code here")
153
- button = st.button("send")
154
- if button or text:
155
- input = tokenizer([text])
156
- out= model(torch.tensor(input.input_ids),torch.tensor(input.attention_mask))
157
- #st.json(out)
158
- st.write(out["my_class"])
159
 
160
 
161
 
162
 
163
-
164
- if __name__ == '__main__':
165
- main()
 
104
 
105
 
106
 
 
 
 
 
 
107
 
108
 
 
 
109
 
110
+ model_name = "Salesforce/codet5p-770m"
111
+ checkpoint = "checkpoint.bin"
112
+
113
+ DEVICE = "cpu"
114
 
115
 
116
 
117
 
118
+ #load tokenizer
119
+ tokenizer = load_tokenizer(model_name)
120
+ print("tokenizer loaded!")
121
 
122
 
123
 
124
 
125
 
126
  #loading model and tokenizer for functional translation
127
+ model = load_model(model_name)
128
 
129
  #adding classification head to the model
130
+ model = adapt_model(model, dim=model.shared.embedding_dim)
131
 
132
 
133
 
134
 
135
 
136
 
137
+ selected = option_menu(
138
  menu_title="Choose your model",
139
  options=["Multilingual_multiprovenance"],
140
  default_index=0,
141
  orientation="horizontal",
142
  )
143
 
144
+ if selected=="Multilingual_standard":
145
+ model.load_state_dict(torch.load(checkpoint,map_location='cpu'))
146
+ model = model.eval()
147
+ st.title("Human-AI stylometer - Multilingual_standard")
148
+ text = st.text_area("insert your code here")
149
+ button = st.button("send")
150
+ if button or text:
151
+ input = tokenizer([text])
152
+ out= model(torch.tensor(input.input_ids),torch.tensor(input.attention_mask))
153
+ #st.json(out)
154
+ st.write(out["my_class"])
155
 
156
 
157
 
158