nickmuchi commited on
Commit
d98d50d
β€’
1 Parent(s): 8f5d5f6

Update pages/3_Earnings_Semantic_Search_πŸ”Ž_.py

Browse files
pages/3_Earnings_Semantic_Search_πŸ”Ž_.py CHANGED
@@ -5,6 +5,10 @@ st.set_page_config(page_title="Earnings Semantic Search", page_icon="πŸ”Ž")
5
  st.sidebar.header("Semantic Search")
6
  st.markdown("## Earnings Semantic Search with SBert")
7
 
 
 
 
 
8
  search_input = st.text_input(
9
  label='Enter Your Search Query',value= "What challenges did the business face?", key='search')
10
 
@@ -13,8 +17,9 @@ top_k = st.sidebar.slider("Number of Top Hits Generated",min_value=1,max_value=5
13
  window_size = st.sidebar.slider("Number of Sentences Generated in Search Response",min_value=1,max_value=5,value=3)
14
 
15
  if search_input:
 
16
 
17
- if any(st.session_state["sen_df"]) is not None and st.session_state["earnings_passages"] is not None:
18
 
19
  ## Save to a dataframe for ease of visualization
20
  sen_df = st.session_state['sen_df']
@@ -44,34 +49,39 @@ if search_input:
44
  score='cross-score'
45
  df = pd.DataFrame([(hit[score],passages[hit['corpus_id']]) for hit in hits[0:int(top_k)]],columns=['Score','Text'])
46
  df['Score'] = round(df['Score'],2)
 
47
 
48
- def gen_annotated_text(para,df=sen_df):
49
- tag_list = []
50
- print(df)
51
- for i in sent_tokenize(para):
52
- print(df.loc[df['text']==i, 'label'])
53
- label = df.loc[df['text']==i, 'label'].values[0]
54
- if label == 'Negative':
55
- tag_list.append((i,label,'#faa'))
56
- elif label == 'Positive':
57
- tag_list.append((i,label,'#afa'))
 
58
  else:
59
- tag_list.append((i,label,'#fea'))
 
60
  return tag_list
61
 
62
- text_to_annotate = [gen_annotated_text(para,sen_df) for para in df.Text.tolist()]
 
 
63
 
64
- first,second = text_to_annotate[0],text_to_annotate[-1]
65
 
66
- with st.container():
67
- annotated_text(*first)
68
 
69
- with st.container():
70
- annotated_text(*second)
71
 
72
  else:
73
 
74
  st.write('Please ensure you have entered the YouTube URL or uploaded the Earnings Call file')
 
75
  else:
76
 
77
  st.write('Please ensure you have entered the YouTube URL or uploaded the Earnings Call file')
 
5
  st.sidebar.header("Semantic Search")
6
  st.markdown("## Earnings Semantic Search with SBert")
7
 
8
+ def gen_sentiment(text):
9
+ '''Generate sentiment of given text'''
10
+ return sent_pipe(text)[0]['label']
11
+
12
  search_input = st.text_input(
13
  label='Enter Your Search Query',value= "What challenges did the business face?", key='search')
14
 
 
17
  window_size = st.sidebar.slider("Number of Sentences Generated in Search Response",min_value=1,max_value=5,value=3)
18
 
19
  if search_input:
20
+
21
 
22
+ if "sen_df" in st.session_state and "earnings_passages" in st.session_state:
23
 
24
  ## Save to a dataframe for ease of visualization
25
  sen_df = st.session_state['sen_df']
 
49
  score='cross-score'
50
  df = pd.DataFrame([(hit[score],passages[hit['corpus_id']]) for hit in hits[0:int(top_k)]],columns=['Score','Text'])
51
  df['Score'] = round(df['Score'],2)
52
+ df['Sentiment'] = df.Text.apply(gen_sentiment)
53
 
54
+ def gen_annotated_text(df):
55
+ '''Generate annotated text'''
56
+
57
+ tag_list=[]
58
+ for row in df.itertuples():
59
+ label = row[3]
60
+ text = row[2]
61
+ if label == 'Positive':
62
+ tag_list.append((text,label,'#8fce00'))
63
+ elif label == 'Negative':
64
+ tag_list.append((text,label,'#f44336'))
65
  else:
66
+ tag_list.append((text,label,'#fff2cc'))
67
+
68
  return tag_list
69
 
70
+ text_annotations = gen_annotated_text(df)
71
+
72
+ first, second = text_annotations[0], text_annotations[1]
73
 
 
74
 
75
+ with st.expander(label='Best Search Query Result', expanded=True):
76
+ annotated_text(first)
77
 
78
+ with st.expander(label='Alternative Search Query Result'):
79
+ annotated_text(second)
80
 
81
  else:
82
 
83
  st.write('Please ensure you have entered the YouTube URL or uploaded the Earnings Call file')
84
+
85
  else:
86
 
87
  st.write('Please ensure you have entered the YouTube URL or uploaded the Earnings Call file')