taskswithcode commited on
Commit
a45b5da
1 Parent(s): e7ea687
Files changed (1) hide show
  1. app.py +14 -7
app.py CHANGED
@@ -7,6 +7,7 @@ import pdb
7
  import json
8
  from twc_embeddings import HFModel,SimCSEModel,SGPTModel
9
  import torch
 
10
 
11
 
12
  MAX_INPUT = 100
@@ -20,28 +21,32 @@ use_case = {"1":"Finding similar phrases/sentences","2":"Retrieving semantically
20
  use_case_url = {"1":"https://huggingface.co/spaces/taskswithcode/semantic_similarity","2":"https://huggingface.co/spaces/taskswithcode/semantic_search","3":""}
21
 
22
 
 
 
23
 
24
 
25
  from transformers import BertTokenizer, BertForMaskedLM
26
 
27
 
28
 
29
- view_count_file = "view_count.txt"
30
 
31
- def get_views():
32
  ret_val = 0
33
  if ("view_count" not in st.session_state):
34
  try:
35
- data = int(open(view_count_file).read().strip("\n"))
 
 
 
36
  except:
37
  data = 0
38
- data += 1
39
- with open(view_count_file,"w") as fp:
40
- fp.write(str(data))
41
  ret_val = data
42
  st.session_state["view_count"] = data
43
  else:
44
  ret_val = st.session_state["view_count"]
 
 
 
45
  return "{:,}".format(ret_val)
46
 
47
 
@@ -155,6 +160,8 @@ def display_results(orig_sentences,main_index,results,response_info,app_mode):
155
  main_sent = main_sent + "\n" + '\n'.join(body_sent)
156
  st.markdown(main_sent,unsafe_allow_html=True)
157
  st.session_state["download_ready"] = json.dumps(download_data,indent=4)
 
 
158
 
159
 
160
  def init_session():
@@ -172,7 +179,7 @@ def app_main(app_mode,example_files,model_name_files):
172
  curr_use_case = use_case[app_mode].split(".")[0]
173
  st.markdown("<h5 style='text-align: center;'>Compare popular/state-of-the-art models for tasks using sentence embeddings</h5>", unsafe_allow_html=True)
174
  st.markdown(f"<div style='color: #4f4f4f; text-align: left'>Use cases for sentence embeddings<br/>&nbsp;&nbsp;&nbsp;•&nbsp;&nbsp;{use_case['1']}<br/>&nbsp;&nbsp;&nbsp;•&nbsp;&nbsp;<a href=\'{use_case_url['2']}\' target='_blank'>{use_case['2']}</a><br/>&nbsp;&nbsp;&nbsp;•&nbsp;&nbsp;{use_case['3']}<br/><i>This app illustrates <b>'{curr_use_case}'</b> use case</i></div>", unsafe_allow_html=True)
175
- st.markdown(f"<div style='color: #9f9f9f; text-align: right'>views:&nbsp;{get_views()}</div>", unsafe_allow_html=True)
176
 
177
 
178
  try:
 
7
  import json
8
  from twc_embeddings import HFModel,SimCSEModel,SGPTModel
9
  import torch
10
+ import requests
11
 
12
 
13
  MAX_INPUT = 100
 
21
  use_case_url = {"1":"https://huggingface.co/spaces/taskswithcode/semantic_similarity","2":"https://huggingface.co/spaces/taskswithcode/semantic_search","3":""}
22
 
23
 
24
+ APP_NAME = "hf/semantic_search"
25
+ INFO_URL = "http://www.taskswithcode.com/stats/"
26
 
27
 
28
  from transformers import BertTokenizer, BertForMaskedLM
29
 
30
 
31
 
 
32
 
33
+ def get_views(action):
34
  ret_val = 0
35
  if ("view_count" not in st.session_state):
36
  try:
37
+ app_info = {'name': APP_NAME,"action":action}
38
+ res = requests.post(INFO_URL, json = app_info).json()
39
+ print(res)
40
+ data = res["count"]
41
  except:
42
  data = 0
 
 
 
43
  ret_val = data
44
  st.session_state["view_count"] = data
45
  else:
46
  ret_val = st.session_state["view_count"]
47
+ if (action != "init"):
48
+ app_info = {'name': APP_NAME,"action":action}
49
+ res = requests.post(INFO_URL, json = app_info).json()
50
  return "{:,}".format(ret_val)
51
 
52
 
 
160
  main_sent = main_sent + "\n" + '\n'.join(body_sent)
161
  st.markdown(main_sent,unsafe_allow_html=True)
162
  st.session_state["download_ready"] = json.dumps(download_data,indent=4)
163
+ get_views("submit")
164
+
165
 
166
 
167
  def init_session():
 
179
  curr_use_case = use_case[app_mode].split(".")[0]
180
  st.markdown("<h5 style='text-align: center;'>Compare popular/state-of-the-art models for tasks using sentence embeddings</h5>", unsafe_allow_html=True)
181
  st.markdown(f"<div style='color: #4f4f4f; text-align: left'>Use cases for sentence embeddings<br/>&nbsp;&nbsp;&nbsp;•&nbsp;&nbsp;{use_case['1']}<br/>&nbsp;&nbsp;&nbsp;•&nbsp;&nbsp;<a href=\'{use_case_url['2']}\' target='_blank'>{use_case['2']}</a><br/>&nbsp;&nbsp;&nbsp;•&nbsp;&nbsp;{use_case['3']}<br/><i>This app illustrates <b>'{curr_use_case}'</b> use case</i></div>", unsafe_allow_html=True)
182
+ st.markdown(f"<div style='color: #9f9f9f; text-align: right'>views:&nbsp;{get_views('init')}</div>", unsafe_allow_html=True)
183
 
184
 
185
  try: