Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -104,55 +104,74 @@ def adapt_model(model:object, dim:int=1024) -> object:
|
|
| 104 |
|
| 105 |
|
| 106 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 107 |
|
| 108 |
|
|
|
|
|
|
|
|
|
|
| 109 |
|
| 110 |
-
|
| 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 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 156 |
|
| 157 |
|
| 158 |
|
|
|
|
|
|
|
|
|
|
|
|
| 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_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 = args.model_name
|
| 116 |
+
checkpoint1 = args.path_checkpoint1
|
| 117 |
+
checkpoint2 = args.path_checkpoint2
|
| 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 |
+
selected = option_menu(
|
| 144 |
menu_title="Choose your model",
|
| 145 |
+
options=["Multilingual_multiprovenance","Multilingual_standard" ],
|
| 146 |
default_index=0,
|
| 147 |
orientation="horizontal",
|
| 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 |
|
| 175 |
+
|
| 176 |
+
if __name__ == '__main__':
|
| 177 |
+
main()
|