NTDuy commited on
Commit
697875a
·
verified ·
1 Parent(s): e161c51

format text

Browse files
Files changed (1) hide show
  1. graphs.py +8 -0
graphs.py CHANGED
@@ -9,9 +9,15 @@ from wordcloud import WordCloud
9
  from underthesea import word_tokenize
10
  import matplotlib.pyplot as plt
11
 
 
12
  def sentence_topic_plot(result):
13
  labels = ["Quality", "Serve", "Pack", "Shipping", "Price", "Other"][::-1]
14
  values = result.detach().numpy()[0][::-1]
 
 
 
 
 
15
  fig = go.Figure()
16
  fig.add_trace(go.Bar(
17
  y=labels,
@@ -19,6 +25,8 @@ def sentence_topic_plot(result):
19
  orientation='h'
20
  ))
21
  fig.update_layout(xaxis_title="Probability", yaxis_title="Topics")
 
 
22
  st.plotly_chart(fig, use_container_width=True)
23
 
24
  def KPI_card(name = "Total Reviews", value = 1000, box_color = (123,167,212), font_color = (0, 0, 0), icon = "fa-list"):
 
9
  from underthesea import word_tokenize
10
  import matplotlib.pyplot as plt
11
 
12
+
13
  def sentence_topic_plot(result):
14
  labels = ["Quality", "Serve", "Pack", "Shipping", "Price", "Other"][::-1]
15
  values = result.detach().numpy()[0][::-1]
16
+ combined = {labels[i] : values[i] for i in range(len(labels))}
17
+ sorted_data = dict(sorted(combined.items(), key=lambda item: item[1]))
18
+ labels = list(sorted_data.keys())
19
+ values = list(sorted_data.values())
20
+ filtered_data = {key: value for key, value in combined.items() if value >= 0.5}
21
  fig = go.Figure()
22
  fig.add_trace(go.Bar(
23
  y=labels,
 
25
  orientation='h'
26
  ))
27
  fig.update_layout(xaxis_title="Probability", yaxis_title="Topics")
28
+ message = ", ".join(i for i in filtered_data.keys())
29
+ st.header(f"Your review is related to :blue[{message}]" )
30
  st.plotly_chart(fig, use_container_width=True)
31
 
32
  def KPI_card(name = "Total Reviews", value = 1000, box_color = (123,167,212), font_color = (0, 0, 0), icon = "fa-list"):