Alex Martin commited on
Commit
2530da6
1 Parent(s): d2159ad

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -2
app.py CHANGED
@@ -19,11 +19,31 @@ sub = st.write("Pick the model to use for analyzing the text!")
19
  button = st.button("Analyze!")
20
  pipe = pipeline("text-classification")
21
  if(button):
 
 
22
  pipe = pipeline("text-classification", model)
23
  results = pipe(text)
24
  st.write(results)
25
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
26
  #TODO: DOCUMENT CODE
27
- #TODO: MAKE THE OUTPUT PRETTIER
28
 
29
 
 
19
  button = st.button("Analyze!")
20
  pipe = pipeline("text-classification")
21
  if(button):
22
+ if model == "aim9061/fine-tuned-toxic-tweet-dilbert":
23
+ get_cats(text)
24
  pipe = pipeline("text-classification", model)
25
  results = pipe(text)
26
  st.write(results)
27
+ def create_dict(prob, text):
28
+ sorted_indices = np.argsort(prob)[-2:]
29
+ info = {"text": text,
30
+ "toxicity": labels[sorted_indices[1]],
31
+ "percentage1": str(round(prob[sorted_indices[1]], 3)),
32
+ "obscenity": labels[sorted_indices[0]],
33
+ "percentage2": str(round(prob[sorted_indices[0]], 3))}
34
+ return info
35
+ def get_cats(text):
36
+ tokenizer = AutoTokenizer.from_pretrained("aim9061/fine-tuned-toxic-tweet-dilbert")
37
+ token = tokenizer(text, return_tensors="pt")
38
+
39
+ outputs = model(**tokens)
40
+
41
+ prob = torch.sigmoid(output.logits).detach().numpy()[0]
42
+
43
+ data = create_dict(prob, text)
44
+ st.table(data)
45
+
46
  #TODO: DOCUMENT CODE
47
+
48
 
49