darthPanda commited on
Commit
41dac9c
1 Parent(s): 5976712
Files changed (2) hide show
  1. app.py +229 -41
  2. requirements.txt +1 -0
app.py CHANGED
@@ -52,6 +52,13 @@ def get_emotion_model():
52
 
53
  tokenizer_emotion,model_emotion = get_emotion_model()
54
 
 
 
 
 
 
 
 
55
  def extract_text_from_pdf(path):
56
  text=''
57
  reader = PdfReader(path)
@@ -81,7 +88,7 @@ if 'filename_key' not in st.session_state:
81
  st.session_state.filename_key = ''
82
 
83
  st.write("""
84
- # Sentiment Analysis Tool
85
  """)
86
  #uploaded_file = st.file_uploader("Choose a PDF file")
87
  #uploaded_file = st.file_uploader("Choose a PDF file", accept_multiple_files=False, type=['pdf'])
@@ -147,24 +154,74 @@ elif len(uploaded_file)>0:
147
  else:
148
  useful_sentence.append(i)
149
 
 
150
  del sentences
151
 
152
- with st.spinner('Performing Sentiment Analysis...'):
153
- tokenizer = tokenizer_sentiment
154
- model = model_sentiment
155
- pipe = pipeline(model="ProsusAI/finbert")
156
- classifier = pipeline(model="ProsusAI/finbert")
157
- output = classifier(useful_sentence)
158
-
159
- with st.spinner('Performing Emotion Analysis...'):
160
- tokenizer = tokenizer_emotion
161
- model = model_emotion
162
- classifier = pipeline("text-classification", model="j-hartmann/emotion-english-distilroberta-base", top_k=1)
163
- temp_emotion = classifier(useful_sentence)
 
 
 
 
 
164
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
165
 
166
- df = pd.DataFrame.from_dict(output)
167
- df['Sentence']= pd.Series(useful_sentence)
168
 
169
  ############################ 3. Processing ############################
170
 
@@ -186,7 +243,10 @@ elif len(uploaded_file)>0:
186
  pos_df = pos_df.sort_values('score', ascending=False)
187
  pos_df_mean = pos_df.score.mean()
188
  pos_df['score'] = pos_df['score'].round(4)
189
- pos_df.rename(columns = {'Sentence':'Positive Sentences'}, inplace = True)
 
 
 
190
 
191
  neg_df = df[df['label']=='negative']
192
  neg_df = neg_df[['score', 'Sentence']]
@@ -194,6 +254,9 @@ elif len(uploaded_file)>0:
194
  neg_df_mean = neg_df.score.mean()
195
  neg_df['score'] = neg_df['score'].round(4)
196
  neg_df.rename(columns = {'Sentence':'Negative Sentences'}, inplace = True)
 
 
 
197
 
198
  neu_df = df[df['label']=='neutral']
199
  neu_df = neu_df[['score', 'Sentence']]
@@ -201,16 +264,15 @@ elif len(uploaded_file)>0:
201
  #neu_df_mean = neu_df.score.mean()
202
  neu_df['score'] = neu_df['score'].round(4)
203
  neu_df.rename(columns = {'Sentence':'Neutral Sentences'}, inplace = True)
 
 
 
204
 
205
  df_temp = neg_df
206
  df_temp = df_temp['score'] * -1
207
  df_temp = pd.concat([df_temp, pos_df])
208
 
209
  ############################ 3.2. Emotion Analysis ############################
210
-
211
- output_emotion = []
212
- for temp in temp_emotion:
213
- output_emotion.append(temp[0])
214
 
215
  df_emotion = pd.DataFrame.from_dict(output_emotion)
216
  df_emotion['Sentence']= pd.Series(useful_sentence)
@@ -250,15 +312,56 @@ elif len(uploaded_file)>0:
250
  num_of_surprise_sentences = df_surprise.shape[0]
251
  if num_of_surprise_sentences == 0:
252
  df_surprise.loc[0] = [0.0, '-------No surprised sentences found in report-------']
253
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
254
  ############################ 4. Plotting ############################
255
 
256
  fig = make_subplots(
257
- rows=41, cols=6,
258
  specs=[ [None, None, None, None, None, None],
259
  [None, None, None, None, None, None],
260
- [None, None, {"type": "indicator", "rowspan": 3, "colspan": 2}, None, None, None],
261
  [None, None, None, None, None, None],
 
262
  [None, None, None, None, None, None],
263
  [{"type": "pie", "rowspan": 6, "colspan": 2}, None, {"type": "indicator", "rowspan": 6, "colspan": 2}, None, {"type": "indicator", "rowspan": 6, "colspan": 2}, None],
264
  [None, None, None, None, None, None],
@@ -278,9 +381,10 @@ elif len(uploaded_file)>0:
278
  [None, None, None, None, None, None],
279
  [None, None, None, None, None, None],
280
  [None, None, None, None, None, None],
281
- [None, None, {"type": "indicator", "rowspan": 3, "colspan": 2}, None, None, None],
282
  [None, None, None, None, None, None],
283
  [None, None, None, None, None, None],
 
 
284
  [None, None, None, None, None, None],
285
  [{"type": "bar", "rowspan": 6, "colspan": 6}, None, None, None, None, None],
286
  [None, None, None, None, None, None],
@@ -296,14 +400,37 @@ elif len(uploaded_file)>0:
296
  [None, None, None, None, None, None],
297
  [None, None, None, None, None, None],
298
  [None, None, None, None, None, None],
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
299
  ],
300
  )
301
 
302
  ############################ 4.1. Sentiment Analysis ############################
 
303
  fig.add_trace(go.Indicator(
304
  mode = "number",
305
- value = None,
306
- title = {"text": "Sentiment Analysis"}), row=3, col=3)
 
 
307
 
308
  colors = px.colors.diverging.Portland#RdBu
309
  fig.add_trace(go.Pie(labels=labels, values=values, hole = 0.5,
@@ -372,15 +499,16 @@ elif len(uploaded_file)>0:
372
  )
373
  fig.add_trace(table_trace2, row=18, col=1)
374
 
375
- fig.add_trace(go.Indicator(
376
- mode = "number",
377
- value = None,
378
- title = {"text": "Emotion Analysis"}), row=24, col=3)
379
 
380
- ############## Under Construction ##############
381
 
382
- ############################ 4.2. Emotion Analysis ############################
383
- #go.Bar(x=['Joy', 'Sadness', 'Anger', 'Surprise'], y=[3, 4, 1])
 
 
 
 
 
 
384
 
385
  # Add bar chart
386
  colors_emotions = ['#174ecf', '#cfc517', '#940625', '#17cfcb']
@@ -397,9 +525,9 @@ elif len(uploaded_file)>0:
397
  marker_color=colors_emotions,
398
  text=annotations,
399
  textfont=dict(size=40)),
400
- row=28, col=1)
401
- fig.update_xaxes(title_text='Emotions', title_font=dict(size=16), row=28, col=1)
402
- fig.update_yaxes(title_text='Number of sentences', title_font=dict(size=16), row=28, col=1)
403
 
404
  # df_anger.loc[0] = [0.0, 'None']
405
  # df_anger
@@ -409,7 +537,7 @@ elif len(uploaded_file)>0:
409
  cells=dict(values=[df_joy[name] for name in df_joy.columns], fill_color='white', align='left'),
410
  columnwidth=[1, 4]
411
  )
412
- fig.add_trace(table_trace2, row=35, col=1)
413
 
414
  ################## sadness table
415
  table_trace2 = go.Table(
@@ -417,7 +545,7 @@ elif len(uploaded_file)>0:
417
  cells=dict(values=[df_sadness[name] for name in df_sadness.columns], fill_color='white', align='left'),
418
  columnwidth=[1, 4]
419
  )
420
- fig.add_trace(table_trace2, row=35, col=4)
421
 
422
  ################## surprise table
423
  table_trace2 = go.Table(
@@ -425,7 +553,7 @@ elif len(uploaded_file)>0:
425
  cells=dict(values=[df_surprise[name] for name in df_surprise.columns], fill_color='white', align='left'),
426
  columnwidth=[1, 4]
427
  )
428
- fig.add_trace(table_trace2, row=38, col=1)
429
 
430
  ################## anger table
431
  table_trace2 = go.Table(
@@ -433,7 +561,66 @@ elif len(uploaded_file)>0:
433
  cells=dict(values=[df_anger[name] for name in df_anger.columns], fill_color='white', align='left'),
434
  columnwidth=[1, 4]
435
  )
436
- fig.add_trace(table_trace2, row=38, col=4)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
437
 
438
  import textwrap
439
  if len(title) > 120:
@@ -443,7 +630,8 @@ elif len(uploaded_file)>0:
443
  # Add HTML tags to force line breaks in the title text
444
  wrapped_title = "<br>".join(wrapped_title.split("\n"))
445
 
446
- fig.update_layout(height=3000, showlegend=False, title={'text': f"<b>{wrapped_title} - Text Analysis Report</b>", 'x': 0.5, 'xanchor': 'center','font': {'size': 32}})
 
447
 
448
  #pyo.plot(fig, filename='report.html')
449
 
 
52
 
53
  tokenizer_emotion,model_emotion = get_emotion_model()
54
 
55
+ @st.cache(allow_output_mutation=True)
56
+ def get_intent_model():
57
+ classifier = pipeline("zero-shot-classification", model='cross-encoder/nli-deberta-v3-small')
58
+ return classifier
59
+
60
+ intent_classifier = get_intent_model()
61
+
62
  def extract_text_from_pdf(path):
63
  text=''
64
  reader = PdfReader(path)
 
88
  st.session_state.filename_key = ''
89
 
90
  st.write("""
91
+ # Dcoument Analysis Tool
92
  """)
93
  #uploaded_file = st.file_uploader("Choose a PDF file")
94
  #uploaded_file = st.file_uploader("Choose a PDF file", accept_multiple_files=False, type=['pdf'])
 
154
  else:
155
  useful_sentence.append(i)
156
 
157
+ useful_sentence_len = len(useful_sentence)
158
  del sentences
159
 
160
+ ############################ 2.1 Sentiment Modeling ############################
161
+ placeholder1 = st.empty()
162
+ placeholder1.text('Performing Sentiment Analysis...')
163
+
164
+ #with st.empty():
165
+ my_bar = st.progress(0)
166
+ tokenizer = tokenizer_sentiment
167
+ model = model_sentiment
168
+ pipe = pipeline(model="ProsusAI/finbert")
169
+ classifier = pipeline(model="ProsusAI/finbert")
170
+ #output = classifier(useful_sentence)
171
+ output=[]
172
+ i=0
173
+ for temp in useful_sentence:
174
+ output.extend(classifier(temp))
175
+ i=i+1
176
+ my_bar.progress(int((i/useful_sentence_len)*100))
177
 
178
+ my_bar.empty()
179
+ df = pd.DataFrame.from_dict(output)
180
+ df['Sentence']= pd.Series(useful_sentence)
181
+
182
+ ############################ 2.2 Emotion Modeling ############################
183
+ #placeholder2 = st.empty()
184
+ placeholder1.text('Performing Emotion Analysis...')
185
+
186
+ # with st.empty():
187
+ my_bar = st.progress(0)
188
+ tokenizer = tokenizer_emotion
189
+ model = model_emotion
190
+ classifier = pipeline("text-classification", model="j-hartmann/emotion-english-distilroberta-base", top_k=1)
191
+ output_emotion = []
192
+ i=0
193
+ for temp in useful_sentence:
194
+ output_emotion.extend(classifier(temp)[0])
195
+ i=i+1
196
+ my_bar.progress(int((i/useful_sentence_len)*100))
197
+
198
+ my_bar.empty()
199
+ placeholder1.text('Emotion Analysis Completed')
200
+
201
+ ############################ 2.3 Intent Modeling ############################
202
+ placeholder1.text('Performing Intent Analysis...')
203
+
204
+ my_bar = st.progress(0)
205
+ candidate_labels = ['complaint', 'suggestion', 'query']
206
+ classifier = intent_classifier
207
+ # temp_intent = classifier(useful_sentence, candidate_labels)
208
+ # output_intent=[]
209
+ # for temp in temp_intent:
210
+ # output_intent.append({'label' : temp['labels'][0], 'score' : temp['scores'][0]})
211
+ output_intent=[]
212
+ i=0
213
+ for temp1 in useful_sentence:
214
+ temp = classifier(temp1, candidate_labels)
215
+ output_intent.append({'label' : temp['labels'][0], 'score' : temp['scores'][0]})
216
+ i=i+1
217
+ my_bar.progress(int((i/useful_sentence_len)*100))
218
+ df_intent = pd.DataFrame.from_dict(output_intent)
219
+ df_intent['Sentence']= pd.Series(useful_sentence)
220
+
221
+ my_bar.empty()
222
+ placeholder1.text('Processing Completed')
223
+
224
 
 
 
225
 
226
  ############################ 3. Processing ############################
227
 
 
243
  pos_df = pos_df.sort_values('score', ascending=False)
244
  pos_df_mean = pos_df.score.mean()
245
  pos_df['score'] = pos_df['score'].round(4)
246
+ pos_df.rename(columns = {'Sentence':'Positive Sentences'}, inplace = True)
247
+ num_of_pos_sentences = pos_df.shape[0]
248
+ if num_of_pos_sentences == 0:
249
+ pos_df.loc[0] = [0.0, '-------No positive sentences found in report-------']
250
 
251
  neg_df = df[df['label']=='negative']
252
  neg_df = neg_df[['score', 'Sentence']]
 
254
  neg_df_mean = neg_df.score.mean()
255
  neg_df['score'] = neg_df['score'].round(4)
256
  neg_df.rename(columns = {'Sentence':'Negative Sentences'}, inplace = True)
257
+ num_of_neg_sentences = neg_df.shape[0]
258
+ if num_of_neg_sentences == 0:
259
+ neg_df.loc[0] = [0.0, '-------No negative sentences found in report-------']
260
 
261
  neu_df = df[df['label']=='neutral']
262
  neu_df = neu_df[['score', 'Sentence']]
 
264
  #neu_df_mean = neu_df.score.mean()
265
  neu_df['score'] = neu_df['score'].round(4)
266
  neu_df.rename(columns = {'Sentence':'Neutral Sentences'}, inplace = True)
267
+ num_of_neu_sentences = neu_df.shape[0]
268
+ if num_of_neu_sentences == 0:
269
+ neu_df.loc[0] = [0.0, '-------No neutral sentences found in report-------']
270
 
271
  df_temp = neg_df
272
  df_temp = df_temp['score'] * -1
273
  df_temp = pd.concat([df_temp, pos_df])
274
 
275
  ############################ 3.2. Emotion Analysis ############################
 
 
 
 
276
 
277
  df_emotion = pd.DataFrame.from_dict(output_emotion)
278
  df_emotion['Sentence']= pd.Series(useful_sentence)
 
312
  num_of_surprise_sentences = df_surprise.shape[0]
313
  if num_of_surprise_sentences == 0:
314
  df_surprise.loc[0] = [0.0, '-------No surprised sentences found in report-------']
315
+
316
+ df_temp_emotion = df_sadness
317
+ df_temp_emotion = pd.concat([df_sadness, df_anger])
318
+ df_temp_emotion = df_temp_emotion['score'] * -1
319
+ df_temp_emotion = pd.concat([df_temp_emotion, df_joy])
320
+
321
+
322
+ ############################ 3.3. Intent Analysis ############################
323
+ df_query = df_intent[df_intent['label']=='query']
324
+ df_query = df_query[['score', 'Sentence']]
325
+ df_query = df_query.sort_values('score', ascending=False)
326
+ df_query['score'] = df_query['score'].round(4)
327
+ df_query.rename(columns = {'Sentence':'Queries'}, inplace = True)
328
+ df_query = df_query[df_query['score']>0.5]
329
+ num_of_queries = df_query.shape[0]
330
+ if num_of_queries == 0:
331
+ df_query.loc[0] = [0.0, '-------No queries found in report-------']
332
+
333
+ df_complaint = df_intent[df_intent['label']=='complaint']
334
+ df_complaint = df_complaint[['score', 'Sentence']]
335
+ df_complaint = df_complaint.sort_values('score', ascending=False)
336
+ df_complaint['score'] = df_complaint['score'].round(4)
337
+ df_complaint.rename(columns = {'Sentence':'Complaints'}, inplace = True)
338
+ df_complaint = df_complaint[df_complaint['score']>0.5]
339
+ num_of_complaints = df_complaint.shape[0]
340
+ if num_of_complaints == 0:
341
+ df_complaint.loc[0] = [0.0, '-------No complaints found in report-------']
342
+
343
+ df_suggestion = df_intent[df_intent['label']=='suggestion']
344
+ df_suggestion = df_suggestion[['score', 'Sentence']]
345
+ df_suggestion = df_suggestion.sort_values('score', ascending=False)
346
+ df_suggestion['score'] = df_suggestion['score'].round(4)
347
+ df_suggestion.rename(columns = {'Sentence':'Suggestions'}, inplace = True)
348
+ df_suggestion = df_suggestion[df_suggestion['score']>0.5]
349
+ num_of_suggestions = df_suggestion.shape[0]
350
+ if num_of_suggestions == 0:
351
+ df_suggestion.loc[0] = [0.0, '-------No suggestions found in report-------']
352
+
353
+ total_num_of_intent = num_of_queries + num_of_complaints + num_of_suggestions
354
+
355
+
356
+
357
  ############################ 4. Plotting ############################
358
 
359
  fig = make_subplots(
360
+ rows=62, cols=6,
361
  specs=[ [None, None, None, None, None, None],
362
  [None, None, None, None, None, None],
 
363
  [None, None, None, None, None, None],
364
+ [None, None, {"type": "indicator", "rowspan": 3, "colspan": 2}, None, None, None],
365
  [None, None, None, None, None, None],
366
  [{"type": "pie", "rowspan": 6, "colspan": 2}, None, {"type": "indicator", "rowspan": 6, "colspan": 2}, None, {"type": "indicator", "rowspan": 6, "colspan": 2}, None],
367
  [None, None, None, None, None, None],
 
381
  [None, None, None, None, None, None],
382
  [None, None, None, None, None, None],
383
  [None, None, None, None, None, None],
 
384
  [None, None, None, None, None, None],
385
  [None, None, None, None, None, None],
386
+ [None, None, {"type": "indicator", "rowspan": 3, "colspan": 2}, None, None, None],
387
+ [None, None, None, None, None, None],
388
  [None, None, None, None, None, None],
389
  [{"type": "bar", "rowspan": 6, "colspan": 6}, None, None, None, None, None],
390
  [None, None, None, None, None, None],
 
400
  [None, None, None, None, None, None],
401
  [None, None, None, None, None, None],
402
  [None, None, None, None, None, None],
403
+ [None, None, None, None, None, None],
404
+ [None, None, {"type": "indicator", "rowspan": 3, "colspan": 2}, None, None, None],
405
+ [None, None, None, None, None, None],
406
+ [None, None, None, None, None, None],
407
+ [None, {"type": "indicator", "rowspan": 2, "colspan": 5}, None, None, None, None],#first bullet
408
+ [None, None, None, None, None, None],
409
+ [None, None, None, None, None, None],
410
+ [None, {"type": "indicator", "rowspan": 2, "colspan": 5}, None, None, None, None], #2nd bullet
411
+ [None, None, None, None, None, None],
412
+ [None, None, None, None, None, None],
413
+ [None, {"type": "indicator", "rowspan": 2, "colspan": 5}, None, None, None, None],
414
+ [None, None, None, None, None, None],
415
+ [None, None, None, None, None, None],
416
+ [{"type": "table", "rowspan": 4, "colspan": 2}, None, {"type": "table", "rowspan": 4, "colspan": 2}, None, {"type": "table", "rowspan": 4, "colspan": 2}, None],
417
+ [None, None, None, None, None, None],
418
+ [None, None, None, None, None, None],
419
+ [None, None, None, None, None, None],
420
+ [None, None, None, None, None, None],
421
+ [None, None, None, None, None, None],
422
+ [None, None, None, None, None, None],
423
  ],
424
  )
425
 
426
  ############################ 4.1. Sentiment Analysis ############################
427
+
428
  fig.add_trace(go.Indicator(
429
  mode = "number",
430
+ value = int(df_temp.score.mean()*100),
431
+ number = {"suffix": "%"},
432
+ title = {"text": "<span style='font-size:1.5em'>Sentiment Analysis</span><br><span style='font-size:0.8em;color:gray'>Positivity Score</span>"}
433
+ ), row=4, col=3)
434
 
435
  colors = px.colors.diverging.Portland#RdBu
436
  fig.add_trace(go.Pie(labels=labels, values=values, hole = 0.5,
 
499
  )
500
  fig.add_trace(table_trace2, row=18, col=1)
501
 
 
 
 
 
502
 
 
503
 
504
+ ########################### 4.2. Emotion Analysis ###########################
505
+
506
+ fig.add_trace(go.Indicator(
507
+ mode = "number",
508
+ value = int(df_temp_emotion.score.mean()*100),
509
+ number = {"suffix": "%"},
510
+ title = {"text": "<span style='font-size:1.5em'>Emotion Analysis</span><br><span style='font-size:0.8em;color:gray'>Happiness Score</span>"}
511
+ ), row=26, col=3)
512
 
513
  # Add bar chart
514
  colors_emotions = ['#174ecf', '#cfc517', '#940625', '#17cfcb']
 
525
  marker_color=colors_emotions,
526
  text=annotations,
527
  textfont=dict(size=40)),
528
+ row=29, col=1)
529
+ fig.update_xaxes(title_text='Emotions', title_font=dict(size=16), row=29, col=1)
530
+ fig.update_yaxes(title_text='Number of sentences', title_font=dict(size=16), row=29, col=1)
531
 
532
  # df_anger.loc[0] = [0.0, 'None']
533
  # df_anger
 
537
  cells=dict(values=[df_joy[name] for name in df_joy.columns], fill_color='white', align='left'),
538
  columnwidth=[1, 4]
539
  )
540
+ fig.add_trace(table_trace2, row=36, col=1)
541
 
542
  ################## sadness table
543
  table_trace2 = go.Table(
 
545
  cells=dict(values=[df_sadness[name] for name in df_sadness.columns], fill_color='white', align='left'),
546
  columnwidth=[1, 4]
547
  )
548
+ fig.add_trace(table_trace2, row=36, col=4)
549
 
550
  ################## surprise table
551
  table_trace2 = go.Table(
 
553
  cells=dict(values=[df_surprise[name] for name in df_surprise.columns], fill_color='white', align='left'),
554
  columnwidth=[1, 4]
555
  )
556
+ fig.add_trace(table_trace2, row=39, col=1)
557
 
558
  ################## anger table
559
  table_trace2 = go.Table(
 
561
  cells=dict(values=[df_anger[name] for name in df_anger.columns], fill_color='white', align='left'),
562
  columnwidth=[1, 4]
563
  )
564
+ fig.add_trace(table_trace2, row=39, col=4)
565
+
566
+
567
+
568
+ ########################### 4.3. Intent Analysis ###########################
569
+
570
+ fig.add_trace(go.Indicator(
571
+ mode = "number",
572
+ value = round(num_of_suggestions/max(num_of_complaints,0), 2),
573
+ number = {"suffix": ""},
574
+ title = {"text": "<span style='font-size:1.5em'>Intent Analysis</span><br><span style='font-size:0.8em;color:gray'>Suggestion/Complaint Ratio</span>"}
575
+ ), row=44, col=3)
576
+
577
+ fig.add_trace(go.Indicator(
578
+ mode = "number+gauge",
579
+ gauge = {'shape': "bullet", 'axis': {'range': [None, total_num_of_intent]}, 'bar': {'color': "blue"}},
580
+ #delta = {'reference': 300},
581
+ value = num_of_queries,
582
+ #domain = {'x': [0.5, 1], 'y': [0.3, 0.9]},
583
+ title = {'text': "Queries"}), row=47, col=2)
584
+
585
+ fig.add_trace(go.Indicator(
586
+ mode = "number+gauge",
587
+ gauge = {'shape': "bullet", 'axis': {'range': [None, total_num_of_intent]},},
588
+ #delta = {'reference': 300},
589
+ value = num_of_suggestions,
590
+ #domain = {'x': [0.5, 1], 'y': [0.3, 0.9]},
591
+ title = {'text': "Suggestions"}), row=50, col=2)
592
+
593
+ fig.add_trace(go.Indicator(
594
+ mode = "number+gauge",
595
+ gauge = {'shape': "bullet", 'axis': {'range': [None, total_num_of_intent]}, 'bar': {'color': "red"}},
596
+ #delta = {'reference': 300},
597
+ value = num_of_complaints,
598
+ #domain = {'x': [0.5, 1], 'y': [0.3, 0.9]},
599
+ title = {'text': "Complaints"}), row=53, col=2)
600
+
601
+ ############ query table
602
+ table_trace2 = go.Table(
603
+ header=dict(values=list(df_query.columns), fill_color='lightgray', align='left'),
604
+ cells=dict(values=[df_query[name] for name in df_query.columns], fill_color='white', align='left'),
605
+ columnwidth=[1, 4]
606
+ )
607
+ fig.add_trace(table_trace2, row=56, col=1)
608
+
609
+ ############ complaints table
610
+ table_trace2 = go.Table(
611
+ header=dict(values=list(df_complaint.columns), fill_color='lightgray', align='left'),
612
+ cells=dict(values=[df_complaint[name] for name in df_complaint.columns], fill_color='white', align='left'),
613
+ columnwidth=[1, 4]
614
+ )
615
+ fig.add_trace(table_trace2, row=56, col=3)
616
+
617
+ ############ suggestions table
618
+ table_trace2 = go.Table(
619
+ header=dict(values=list(df_suggestion.columns), fill_color='lightgray', align='left'),
620
+ cells=dict(values=[df_suggestion[name] for name in df_suggestion.columns], fill_color='white', align='left'),
621
+ columnwidth=[1, 4]
622
+ )
623
+ fig.add_trace(table_trace2, row=56, col=5)
624
 
625
  import textwrap
626
  if len(title) > 120:
 
630
  # Add HTML tags to force line breaks in the title text
631
  wrapped_title = "<br>".join(wrapped_title.split("\n"))
632
 
633
+ fig.update_layout(height=4000, showlegend=False, title={'text': f"<b>{wrapped_title} - Text Analysis Report</b>", 'x': 0.5, 'xanchor': 'center','font': {'size': 32}})
634
+
635
 
636
  #pyo.plot(fig, filename='report.html')
637
 
requirements.txt CHANGED
@@ -1,5 +1,6 @@
1
  streamlit==1.17.0
2
  transformers
 
3
  torch
4
  PyPDF2
5
  nltk
 
1
  streamlit==1.17.0
2
  transformers
3
+ sentencepiece
4
  torch
5
  PyPDF2
6
  nltk