Delete app.py
Browse files
app.py
DELETED
@@ -1,47 +0,0 @@
|
|
1 |
-
import streamlit as st
|
2 |
-
|
3 |
-
def main():
|
4 |
-
st.title("Classification de séquence")
|
5 |
-
|
6 |
-
title = st.text_input("Titre")
|
7 |
-
post = st.text_area("Post")
|
8 |
-
comment = st.text_area("Commentaire")
|
9 |
-
|
10 |
-
# Bouton Tester
|
11 |
-
if st.button("Tester"):
|
12 |
-
result = classify(title, post, comment)
|
13 |
-
st.success(result)
|
14 |
-
|
15 |
-
def classify(title,post,comment):
|
16 |
-
|
17 |
-
from transformers import DistilBertTokenizer,AutoModelForSequenceClassification
|
18 |
-
import torch
|
19 |
-
state_dict=torch.load(f"./ipcbert")
|
20 |
-
tokenizer=RobertaBertTokenizer.from_pretrained("distil-base-uncased")
|
21 |
-
model = AutoModelForSequenceClassification.from_pretrained('distil-bert-uncased',
|
22 |
-
problem_type="multi_label_classification",
|
23 |
-
num_labels=3
|
24 |
-
)
|
25 |
-
model.load_state_dict(state_dict)
|
26 |
-
device = torch.device("cpu")
|
27 |
-
model.to(device)
|
28 |
-
|
29 |
-
model.eval()
|
30 |
-
inputs = tokenizer("title of the post: "+title+"\n"+"post: "+post+"\n"+"comment: "+commentaire, return_tensors="pt", padding=True, truncation=True, max_length=512)
|
31 |
-
input_ids = inputs['input_ids'].to(device)
|
32 |
-
attention_mask = inputs['attention_mask'].to(device)
|
33 |
-
|
34 |
-
with torch.no_grad():
|
35 |
-
outputs = model(input_ids, attention_mask=attention_mask)
|
36 |
-
logits = outputs.logits
|
37 |
-
_, preds = torch.max(logits, dim=1)
|
38 |
-
id2label={
|
39 |
-
0:"neutral",
|
40 |
-
1:"with palestine",
|
41 |
-
2:"with israel"
|
42 |
-
}
|
43 |
-
return id2label[preds.item()]
|
44 |
-
|
45 |
-
if __name__ == "__main__":
|
46 |
-
main()
|
47 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|