pleonova commited on
Commit
eccb736
1 Parent(s): b4ff267

Comment out plotly

Browse files
Files changed (1) hide show
  1. utils.py +39 -39
utils.py CHANGED
@@ -1,56 +1,56 @@
1
  import streamlit as st
2
  import numpy as np
3
  import pandas as pd
4
- import plotly.express as px
5
- from plotly.subplots import make_subplots
6
  import json
7
 
8
  # Reference: https://huggingface.co/spaces/team-zero-shot-nli/zero-shot-nli/blob/main/utils.py
9
- def plot_result(top_topics, scores):
10
- top_topics = np.array(top_topics)
11
- scores = np.array(scores)
12
- scores *= 100
13
- fig = px.bar(x=np.around(scores,2), y=top_topics, orientation='h',
14
- labels={'x': 'Confidence Score', 'y': 'Label'},
15
- text=scores,
16
- range_x=(0,115),
17
- title='Predictions',
18
- color=np.linspace(0,1,len(scores)),
19
- color_continuous_scale='GnBu')
20
- fig.update(layout_coloraxis_showscale=False)
21
- fig.update_traces(texttemplate='%{text:0.1f}%', textposition='outside')
22
- st.plotly_chart(fig)
23
 
24
 
25
- def plot_dual_bar_chart(topics_summary, scores_summary, topics_text, scores_text):
26
- data1 = pd.DataFrame({'label': topics_summary, 'scores on summary': scores_summary})
27
- data2 = pd.DataFrame({'label': topics_text, 'scores on full text': scores_text})
28
- data = pd.merge(data1, data2, on = ['label'])
29
- data.sort_values('scores on summary', ascending = True, inplace = True)
30
 
31
- fig = make_subplots(rows=1, cols=2,
32
- subplot_titles=("Predictions on Summary", "Predictions on Full Text"),
33
- )
34
 
35
- fig1 = px.bar(x=round(data['scores on summary']*100, 2), y=data['label'], orientation='h',
36
- text=round(data['scores on summary']*100, 2),
37
- )
38
 
39
- fig2 = px.bar(x=round(data['scores on full text']*100,2), y=data['label'], orientation='h',
40
- text=round(data['scores on full text']*100,2),
41
- )
42
 
43
- fig.add_trace(fig1['data'][0], row=1, col=1)
44
- fig.add_trace(fig2['data'][0], row=1, col=2)
45
 
46
- fig.update_traces(texttemplate='%{text:0.1f}%', textposition='outside')
47
- fig.update_layout(height=600, width=700) #, title_text="Predictions for")
48
- fig.update_xaxes(range=[0,115])
49
- fig.update_xaxes(matches='x')
50
- fig.update_yaxes(showticklabels=False) # hide all the xticks
51
- fig.update_yaxes(showticklabels=True, row=1, col=1)
52
 
53
- st.plotly_chart(fig)
54
 
55
  # def plot_dual_bar_chart(topics_summary, scores_summary, topics_text, scores_text):
56
  # data1 = pd.DataFrame({'label': topics_summary, 'scores': scores_summary})
1
  import streamlit as st
2
  import numpy as np
3
  import pandas as pd
4
+ # import plotly.express as px
5
+ # from plotly.subplots import make_subplots
6
  import json
7
 
8
  # Reference: https://huggingface.co/spaces/team-zero-shot-nli/zero-shot-nli/blob/main/utils.py
9
+ # def plot_result(top_topics, scores):
10
+ # top_topics = np.array(top_topics)
11
+ # scores = np.array(scores)
12
+ # scores *= 100
13
+ # fig = px.bar(x=np.around(scores,2), y=top_topics, orientation='h',
14
+ # labels={'x': 'Confidence Score', 'y': 'Label'},
15
+ # text=scores,
16
+ # range_x=(0,115),
17
+ # title='Predictions',
18
+ # color=np.linspace(0,1,len(scores)),
19
+ # color_continuous_scale='GnBu')
20
+ # fig.update(layout_coloraxis_showscale=False)
21
+ # fig.update_traces(texttemplate='%{text:0.1f}%', textposition='outside')
22
+ # st.plotly_chart(fig)
23
 
24
 
25
+ # def plot_dual_bar_chart(topics_summary, scores_summary, topics_text, scores_text):
26
+ # data1 = pd.DataFrame({'label': topics_summary, 'scores on summary': scores_summary})
27
+ # data2 = pd.DataFrame({'label': topics_text, 'scores on full text': scores_text})
28
+ # data = pd.merge(data1, data2, on = ['label'])
29
+ # data.sort_values('scores on summary', ascending = True, inplace = True)
30
 
31
+ # fig = make_subplots(rows=1, cols=2,
32
+ # subplot_titles=("Predictions on Summary", "Predictions on Full Text"),
33
+ # )
34
 
35
+ # fig1 = px.bar(x=round(data['scores on summary']*100, 2), y=data['label'], orientation='h',
36
+ # text=round(data['scores on summary']*100, 2),
37
+ # )
38
 
39
+ # fig2 = px.bar(x=round(data['scores on full text']*100,2), y=data['label'], orientation='h',
40
+ # text=round(data['scores on full text']*100,2),
41
+ # )
42
 
43
+ # fig.add_trace(fig1['data'][0], row=1, col=1)
44
+ # fig.add_trace(fig2['data'][0], row=1, col=2)
45
 
46
+ # fig.update_traces(texttemplate='%{text:0.1f}%', textposition='outside')
47
+ # fig.update_layout(height=600, width=700) #, title_text="Predictions for")
48
+ # fig.update_xaxes(range=[0,115])
49
+ # fig.update_xaxes(matches='x')
50
+ # fig.update_yaxes(showticklabels=False) # hide all the xticks
51
+ # fig.update_yaxes(showticklabels=True, row=1, col=1)
52
 
53
+ # st.plotly_chart(fig)
54
 
55
  # def plot_dual_bar_chart(topics_summary, scores_summary, topics_text, scores_text):
56
  # data1 = pd.DataFrame({'label': topics_summary, 'scores': scores_summary})