Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -105,70 +105,38 @@ def adapt_model(model:object, dim:int=1024) -> object:
|
|
105 |
|
106 |
|
107 |
def main():
|
108 |
-
|
109 |
-
parser.add_argument('--model_name', type=str, default="Salesforce/codet5p-770m")
|
110 |
-
parser.add_argument('--path_checkpoint1', type=str, default="checkpoint.bin")
|
111 |
-
parser.add_argument('--path_checkpoint2', type=str, default="multilingual_standard.bin")
|
112 |
-
args = parser.parse_args()
|
113 |
|
114 |
|
115 |
-
model_name =
|
116 |
-
|
117 |
-
|
118 |
|
119 |
DEVICE = "cpu"
|
120 |
|
121 |
-
|
122 |
-
|
123 |
|
124 |
#load tokenizer
|
125 |
tokenizer = load_tokenizer(model_name)
|
126 |
print("tokenizer loaded!")
|
127 |
-
|
128 |
-
|
129 |
|
130 |
|
131 |
-
|
132 |
-
#loading model and tokenizer for functional translation
|
133 |
model = load_model(model_name)
|
134 |
-
|
135 |
-
#adding classification head to the model
|
136 |
model = adapt_model(model, dim=model.shared.embedding_dim)
|
137 |
|
138 |
|
139 |
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
if selected=="Multilingual_standard":
|
151 |
-
model.load_state_dict(torch.load(checkpoint2,map_location='cpu'))
|
152 |
-
model = model.eval()
|
153 |
-
st.title("Human-AI stylometer - Multilingual_standard")
|
154 |
-
text = st.text_area("insert your code here")
|
155 |
-
button = st.button("send")
|
156 |
-
if button or text:
|
157 |
-
input = tokenizer([text])
|
158 |
-
out= model(torch.tensor(input.input_ids),torch.tensor(input.attention_mask))
|
159 |
-
#st.json(out)
|
160 |
-
st.write(out["my_class"])
|
161 |
-
else:
|
162 |
-
model.load_state_dict(torch.load(checkpoint1,map_location='cpu'))
|
163 |
-
model = model.eval()
|
164 |
-
st.title("Human-AI stylometer - Multilingual_multiprovenance")
|
165 |
-
text = st.text_area("insert your code here")
|
166 |
-
button = st.button("send")
|
167 |
-
if button or text:
|
168 |
-
input = tokenizer([text])
|
169 |
-
out= model(torch.tensor(input.input_ids),torch.tensor(input.attention_mask))
|
170 |
-
#st.json(out)
|
171 |
-
st.write(out["my_class"])
|
172 |
|
173 |
|
174 |
|
|
|
105 |
|
106 |
|
107 |
def main():
|
108 |
+
print("----starting enviroment----")
|
|
|
|
|
|
|
|
|
109 |
|
110 |
|
111 |
+
model_name = "Salesforce/codet5p-770m"
|
112 |
+
checkpoint = "checkpoint.bin"
|
113 |
+
|
114 |
|
115 |
DEVICE = "cpu"
|
116 |
|
117 |
+
|
|
|
118 |
|
119 |
#load tokenizer
|
120 |
tokenizer = load_tokenizer(model_name)
|
121 |
print("tokenizer loaded!")
|
|
|
|
|
122 |
|
123 |
|
124 |
+
#loading model and tokenizer for functional translation
|
|
|
125 |
model = load_model(model_name)
|
126 |
+
#adding classification head to the model
|
|
|
127 |
model = adapt_model(model, dim=model.shared.embedding_dim)
|
128 |
|
129 |
|
130 |
|
131 |
+
model.load_state_dict(torch.load(checkpoint,map_location='cpu'))
|
132 |
+
model = model.eval()
|
133 |
+
st.title("Human-AI stylometer - Multilingual_multiprovenance")
|
134 |
+
text = st.text_area("insert your code here")
|
135 |
+
button = st.button("send")
|
136 |
+
if button or text:
|
137 |
+
input = tokenizer([text])
|
138 |
+
out= model(torch.tensor(input.input_ids),torch.tensor(input.attention_mask))
|
139 |
+
st.write(out["my_class"])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
140 |
|
141 |
|
142 |
|