Mayureshd commited on
Commit
7d81008
1 Parent(s): 8f716e5

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +72 -0
app.py ADDED
@@ -0,0 +1,72 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pandas as pd
2
+ import numpy as np
3
+ import streamlit as st
4
+
5
+ from transformers import AutoModelForQuestionAnswering, AutoTokenizer, pipeline
6
+
7
+ model_name = "deepset/roberta-base-squad2"
8
+
9
+ # a) Get predictions
10
+ nlp = pipeline('question-answering', model=model_name, tokenizer=model_name)
11
+
12
+ # b) Load model & tokenizer
13
+ model = AutoModelForQuestionAnswering.from_pretrained(model_name)
14
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
15
+
16
+
17
+ suspicious_words = [
18
+ "robbery", "crime", "exchange", "extortion", "threat", "suspicious", "fraud", "laundering",
19
+ "illegal", "contraband", "smuggling", "burglary", "assault", "hijacking", "kidnapping", "ransom",
20
+ "hostage", "terrorism", "homicide", "murder", "manslaughter", "weapon", "gun", "explosive", "bomb", "knives",
21
+ "threaten", "blackmail", "intimidate", "menace", "harassment", "stalking", "kidnap", "abduction", "guns", "bombs",
22
+ "abuse", "trafficking", "prostitution", "pimping", "drug", "narcotic", "cocaine", "heroin", "methamphetamine",
23
+ "amphetamine", "opiate", "meth", "gang", "gangster", "mafia", "racket", "extort", "embezzle", "corruption",
24
+ "bribe", "scam", "forgery", "counterfeit", "fraudulent", "cybercrime", "hacker", "phishing", "identity", "theft",
25
+ "credit card", "fraud", "identity", "fraud", "ponzi", "scheme", "pyramid", "scheme", "money", "scam", "swindle", "deception",
26
+ "conspiracy", "scheme", "plot", "coercion", "corrupt", "criminal", "felony", "misdemeanor", "felon", "fugitive",
27
+ "wanted", "arson", "arsonist", "arsony", "stolen", "steal", "loot", "heist", "launder", "hitman", "racketeer",
28
+ "hijack", "smuggle", "terrorist", "kidnapper", "perpetrator", "ringleader", "prowler", "vigilante", "sabotage",
29
+ "saboteur", "suicide", "discreet", "hide", "action", "profile", "alert", "vigilant", "clandestine", "riot", "arms", "deal"
30
+ ]
31
+
32
+
33
+ q = ["","",""]
34
+ a = ["","",""]
35
+
36
+
37
+ q[0] = "What event is going to take place?"
38
+ q[1] = "Where is it going to happen"
39
+ q[2] = "What time is it going to happen?"
40
+
41
+
42
+ QA_input = [{} for i in range(3)]
43
+ res = [{} for i in range(3)]
44
+
45
+
46
+ sentence=st.text_area("Enter your sentence")
47
+
48
+ for i in range(3):
49
+ QA_input[i] = {
50
+ 'question': q[i],
51
+ 'context': sentence
52
+ }
53
+ res[i] = nlp(QA_input[i])
54
+ a[i] = res[i]['answer']
55
+
56
+ a1 = a[0].lower()
57
+ a1s = set(a1.split())
58
+ sus = set(suspicious_words)
59
+ cw = a1s.intersection(sus)
60
+
61
+ if len(cw) != 0:
62
+ st.write("The crime detected is: ",a[0])
63
+ if len(a[1]) != 0:
64
+ st.write("The location of crime detected is: ",a[1])
65
+ elif len(a[1]) == 0:
66
+ st.write("No location detected")
67
+ if len(a[2]) != 0:
68
+ st.write("The time of crime detected is: ",a[2])
69
+ elif len(a[2]) == 0:
70
+ st.write("No time detected")
71
+ elif len(cw) == 0:
72
+ st.write("No crime detected")