siddhantuniyal commited on
Commit
e93974b
1 Parent(s): 4a4ab11

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -139
app.py CHANGED
@@ -1,151 +1,18 @@
1
- # import matplotlib.pyplot as plt
2
- # import nltk
3
- # import spacy
4
- # from nltk.sentiment.vader import SentimentIntensityAnalyzer
5
  from transformers import pipeline
6
  import gradio as gr
7
  import tensorflow
8
- # # from reportlab.lib.pagesizes import letter
9
- # # from reportlab.platypus import SimpleDocTemplate, Image
10
-
11
- # nltk.download('vader_lexicon')
12
-
13
- # feedbacks = [
14
- # "I had a great experience with Inspector Sharma during my visit to the police station. He was very helpful and professional.",
15
- # "My experience at the police station was terrible. The officer on duty was rude and uncooperative.",
16
- # "I want to express my gratitude to Constable Patel for his prompt response to my complaint. He did an excellent job.",
17
- # "I appreciate the efforts of Sub-Inspector Khan in solving my case quickly and efficiently. He demonstrated great problem-solving skills.",
18
- # "I had a bad experience at the police station. Officer Gupta was dismissive and didn't take my complaint seriously.",
19
- # "I'm thankful to Officer Joshi for helping me with my case. However, the wait time at the police station was excessive, and that needs improvement.",
20
- # "I would like to acknowledge the hard work of ACP Singh in maintaining law and order in our area. His dedication is commendable.",
21
- # "My recent interaction with the police station was satisfactory. No complaints, but no exceptional service either.",
22
- # "I want to express my appreciation to Officer Mehta and Officer Reddy for their quick response to my emergency call. They handled the situation well.",
23
- # "I had a positive experience at the police station. Constable Gupta was helpful, but there was some confusion regarding the paperwork that could be streamlined.",
24
- # "My interaction with Officer Kapoor and Officer Sharma was neither good nor bad. It was an average experience with no exceptional service.",
25
- # "I had a positive experience with Constable Verma. His prompt action was much appreciated.",
26
- # "I had an unpleasant experience with Officer Kapoor. He was uncooperative and dismissive of my complaint.",
27
- # "Constable Patel provided exceptional service during my visit to the police station. I was impressed with his professionalism.",
28
- # "My recent interaction with the police station left much to be desired. The officers seemed disorganized and unresponsive.",
29
- # "I had a smooth experience at the police station. No complaints, and the staff was polite and efficient.",
30
- # "I appreciate the dedication of Officer Sharma in ensuring the safety of our community. He is an asset to the police force.",
31
- # "The service at the police station was disappointing. Officer Gupta was rude and unhelpful.",
32
- # "I'm grateful to Sub-Inspector Khan for his assistance in resolving my case. He went above and beyond to help me.",
33
- # "Officer Reddy was exceptionally helpful during my recent visit to the police station. I'm thankful for his support.",
34
- # "My experience at the police station was unremarkable. The officers did their job, but there was no exceptional service.",
35
- # "I had a positive experience with Constable Verma, who handled my case with professionalism and efficiency.",
36
- # "I had a negative experience with Officer Joshi. He was unresponsive and didn't take my concerns seriously.",
37
- # "The police station needs improvement in terms of service. My recent visit was less than satisfactory.",
38
- # "I'm satisfied with the service provided by ACP Singh in our area. He ensures our safety and well-being.",
39
- # "I had a disappointing experience at the police station. The officers were uncooperative and unprofessional.",
40
- # "I want to acknowledge the hard work of Constable Patel. He is an excellent officer and deserves recognition.",
41
- # "I had a mixed experience at the police station. Some aspects were positive, while others need improvement.",
42
- # "Officer Mehta provided prompt and efficient assistance during my visit to the police station. I'm thankful for his support.",
43
- # "My recent interaction with the police station was average. There were no major issues, but nothing exceptional either."
44
- # ]
45
-
46
- # additional_feedbacks = [
47
- # "Officer Reddy and Officer Joshi were both helpful during my recent visit to the police station. They provided the support I needed.",
48
- # "I had a positive experience with Officer Mehta and Officer Reddy. Their teamwork was evident in resolving my case.",
49
- # "Constable Patel and Officer Gupta were uncooperative during my recent visit. The service was disappointing.",
50
- # "Officer Kapoor's behavior was unprofessional during my visit to the police station. I expected better service.",
51
- # "I appreciate the assistance of Sub-Inspector Khan and Officer Mehta. They worked together to resolve my complaint.",
52
- # "I had a negative experience with Constable Patel. He was dismissive and unhelpful.",
53
- # "Officer Sharma and ACP Singh both played crucial roles in maintaining law and order in our area. Their dedication is commendable.",
54
- # "My recent interaction with Officer Joshi and Officer Reddy was satisfactory. They handled my concerns efficiently.",
55
- # "I had an average experience at the police station. Officer Mehta and Constable Verma provided service without any exceptional aspects.",
56
- # "I had a mixed experience with Officer Gupta and Officer Sharma. While they were professional, the process needs improvement.",
57
- # ]
58
- # gujarat_feedbacks = [
59
- # "I had a positive experience at Gandhinagar Police Station. The officers were helpful and efficient.",
60
- # "My visit to Ahmedabad Police Station was satisfactory. The staff handled my complaint professionally.",
61
- # "I appreciate the service at Surat Police Station. They resolved my case promptly.",
62
- # "Officer Patel at Vadodara Police Station provided exceptional assistance. I'm grateful for their support.",
63
- # "My recent interaction with Rajkot Police Station was good. They ensured our safety effectively.",
64
- # "I had a mixed experience at Junagadh Police Station. Some aspects were positive, while others need improvement.",
65
- # "The police station in Bhavnagar is in need of better service. My recent visit was disappointing.",
66
- # "I had a positive experience with Officer Mehta at Anand Police Station. Their prompt action was much appreciated.",
67
- # "I want to acknowledge the hard work of the officers at Jamnagar Police Station. Their dedication is commendable.",
68
- # "Officer Joshi at Patan Police Station was exceptionally helpful. I'm thankful for their support.",
69
- # "I had a negative experience at Porbandar Police Station. The officers were unresponsive and unprofessional.",
70
- # "The police station in Nadiad needs improvement. My recent visit was less than satisfactory.",
71
- # "I'm satisfied with the service provided by the police in Bharuch, Gujarat. They ensure our safety and well-being.",
72
- # "I had an unpleasant experience at the police station in Anand. The officers were dismissive and uncooperative.",
73
- # "Officer Sharma at Vadodara Police Station was professional and efficient. I had a positive experience.",
74
- # "I had a smooth experience at the police station in Rajkot. No complaints, and the staff was polite and efficient.",
75
- # "I appreciate the dedication of the officers at Surat Police Station. They maintain law and order effectively.",
76
- # "My experience at the police station in Bhuj was unremarkable. The officers did their job, but there was no exceptional service.",
77
- # "I want to express my gratitude to the officers at Bhavnagar Police Station for their prompt response to my complaint.",
78
- # "Officer Desai at Porbandar Police Station was helpful and professional during my visit. I had a good experience.",
79
- # "My recent interaction with the police in Jamnagar was satisfactory. The officers handled my concerns efficiently.",
80
- # "The service at Bhuj Police Station was disappointing. Officer Shah was unhelpful and rude during my visit.",
81
- # "I'm thankful to Officer Patel at Gandhinagar Police Station for helping me with my case. Their prompt response was appreciated.",
82
- # "My visit to the police station in Anand, Gujarat, was terrible. The officer on duty was dismissive and uncooperative.",
83
- # "Officer Pandya at Junagadh Police Station provided excellent assistance. I want to express my gratitude for their support.",
84
- # "My recent interaction with the police in Surat was less than satisfactory. The officers seemed disorganized and unresponsive.",
85
- # "I had a good experience at Rajkot Police Station. The officers were professional and handled my case effectively.",
86
- # "I had an average experience at the police station in Gandhinagar. The service was neither good nor bad.",
87
- # "The police station in Bharuch needs improvement. My recent visit was disappointing, and the service was lacking.",
88
- # "Officer Mehta at Bhavnagar Police Station was helpful and professional. I appreciate their dedication to their job.",
89
- # "I had a mixed experience at Ahmedabad Police Station. Some aspects were positive, while others need improvement.",
90
- # "I'm grateful for the service provided by the police in Vadodara, Gujarat. They ensure the safety of our community.",
91
- # ]
92
-
93
- # feedbacks += gujarat_feedbacks
94
-
95
 
96
- # feedbacks += additional_feedbacks
97
 
98
- issues = ["Misconduct" , "Negligence" , "Discrimination" , "Corruption" , "Violation of Rights" , "Inefficiency" ,
99
  "Unprofessional Conduct", "Response Time" , "Use of Firearms" , "Property Damage"]
100
 
101
 
102
- groupByType = TFDebertaForSequenceClassification.from_pretrained(model_name, from_pt=True)
103
-
104
-
105
-
106
- # pos_count = 0
107
- # neg_count = 0
108
- # neutral_count = 0
109
-
110
-
111
- # report = {}
112
-
113
-
114
-
115
- # ner = spacy.load("en_core_web_sm")
116
-
117
- # for feedback in feedbacks:
118
- # # location = ""
119
- # # doc = ner(feedback)
120
- # # for ent in doc.ents:
121
- # # if ent.label_=='GPE':
122
- # # location = ent.text.lower()
123
- # # if location not in report:
124
- # # report[location] = [[0,0,0] , []]
125
-
126
- # # if location:
127
-
128
- # # score = SentimentIntensityAnalyzer().polarity_scores(feedback)
129
- # # sentiment = max(score , key = score.get)
130
- # # if sentiment == 'pos':
131
- # # report[location][0][0]+=1
132
- # # elif sentiment == 'neg':
133
- # # report[location][0][1]+=1
134
- # # else:
135
- # # report[location][0][2]+=1
136
-
137
- # # report[location][1].append(groupByType(feedback , candidate_labels = issues)['labels'][0])
138
- # report[feedback] = groupByType(feedback , candidate_labels = issues)['labels'][0]
139
-
140
-
141
-
142
-
143
- # # print(report)
144
-
145
-
146
 
147
- def zeroshotclassification(feedback):
148
- issue = groupByType(feedback , candidate_labels = issues , multi_label = False)['labels'][0]
149
  return issue
150
 
151
  iface = gr.Interface(
 
1
+
 
 
 
2
  from transformers import pipeline
3
  import gradio as gr
4
  import tensorflow
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
 
6
+ model_name = "facebook/bart-large-mnli"
7
 
8
+ class_labels = ["Misconduct" , "Negligence" , "Discrimination" , "Corruption" , "Violation of Rights" , "Inefficiency" ,
9
  "Unprofessional Conduct", "Response Time" , "Use of Firearms" , "Property Damage"]
10
 
11
 
12
+ classifier = pipeline("zero-shot-classification", model=model_name)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13
 
14
+ def zeroshotclassification(input_text):
15
+ issue = classifier(input_text , class_labels , multi_label = False)['labels'][0]
16
  return issue
17
 
18
  iface = gr.Interface(