taskswithcode commited on
Commit
9cac99a
1 Parent(s): 93c89d0
Files changed (1) hide show
  1. app.py +18 -7
app.py CHANGED
@@ -7,6 +7,7 @@ import pdb
7
  import json
8
  from twc_embeddings import HFModel,SimCSEModel,SGPTModel,CausalLMModel,SGPTQnAModel
9
  import torch
 
10
 
11
 
12
  MAX_INPUT = 100
@@ -24,27 +25,36 @@ use_case_url = {"1":"https://huggingface.co/spaces/taskswithcode/semantic_simila
24
  from transformers import BertTokenizer, BertForMaskedLM
25
 
26
 
 
 
27
 
28
- view_count_file = "view_count.txt"
29
 
30
- def get_views():
 
 
 
31
  ret_val = 0
32
  if ("view_count" not in st.session_state):
33
  try:
34
- data = int(open(view_count_file).read().strip("\n"))
 
 
 
 
35
  except:
36
  data = 0
37
- data += 1
38
  ret_val = data
39
  st.session_state["view_count"] = data
40
- with open(view_count_file,"w") as fp:
41
- fp.write(str(data))
42
  else:
43
  ret_val = st.session_state["view_count"]
 
 
 
44
  return "{:,}".format(ret_val)
45
 
46
 
47
 
 
48
  def construct_model_info_for_display(model_names):
49
  options_arr = []
50
  markdown_str = f"<div style=\"font-size:16px; color: #2f2f2f; text-align: left\"><br/><b>Models evaluated ({len(model_names)})</b></div>"
@@ -154,6 +164,7 @@ def display_results(orig_sentences,main_index,results,response_info,app_mode):
154
  main_sent = main_sent + "\n" + '\n'.join(body_sent)
155
  st.markdown(main_sent,unsafe_allow_html=True)
156
  st.session_state["download_ready"] = json.dumps(download_data,indent=4)
 
157
 
158
 
159
  def init_session():
@@ -171,7 +182,7 @@ def app_main(app_mode,example_files,model_name_files):
171
  curr_use_case = use_case[app_mode].split(".")[0]
172
  st.markdown("<h5 style='text-align: center;'>Compare popular/state-of-the-art models for tasks using sentence embeddings</h5>", unsafe_allow_html=True)
173
  st.markdown(f"<div style='color: #4f4f4f; text-align: left'>Use cases for sentence embeddings<br/>&nbsp;&nbsp;&nbsp;•&nbsp;&nbsp;<a href=\'{use_case_url['1']}\' target='_blank'>{use_case['1']}</a><br/>&nbsp;&nbsp;&nbsp;•&nbsp;&nbsp;{use_case['2']}<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)
174
- st.markdown(f"<div style='color: #9f9f9f; text-align: right'>views:&nbsp;{get_views()}</div>", unsafe_allow_html=True)
175
 
176
 
177
  try:
 
7
  import json
8
  from twc_embeddings import HFModel,SimCSEModel,SGPTModel,CausalLMModel,SGPTQnAModel
9
  import torch
10
+ import requests
11
 
12
 
13
  MAX_INPUT = 100
 
25
  from transformers import BertTokenizer, BertForMaskedLM
26
 
27
 
28
+ APP_NAME = "hf/semantic_search"
29
+ INFO_URL = "http://www.taskswithcode.com/stats/"
30
 
 
31
 
32
+
33
+
34
+ def get_views(action):
35
+ print("in get views",action)
36
  ret_val = 0
37
  if ("view_count" not in st.session_state):
38
  try:
39
+ print("inside get views")
40
+ app_info = {'name': APP_NAME,"action":action}
41
+ res = requests.post(INFO_URL, json = app_info).json()
42
+ print(res)
43
+ data = res["count"]
44
  except:
45
  data = 0
 
46
  ret_val = data
47
  st.session_state["view_count"] = data
 
 
48
  else:
49
  ret_val = st.session_state["view_count"]
50
+ if (action != "init"):
51
+ app_info = {'name': APP_NAME,"action":action}
52
+ res = requests.post(INFO_URL, json = app_info).json()
53
  return "{:,}".format(ret_val)
54
 
55
 
56
 
57
+
58
  def construct_model_info_for_display(model_names):
59
  options_arr = []
60
  markdown_str = f"<div style=\"font-size:16px; color: #2f2f2f; text-align: left\"><br/><b>Models evaluated ({len(model_names)})</b></div>"
 
164
  main_sent = main_sent + "\n" + '\n'.join(body_sent)
165
  st.markdown(main_sent,unsafe_allow_html=True)
166
  st.session_state["download_ready"] = json.dumps(download_data,indent=4)
167
+ get_views("submit")
168
 
169
 
170
  def init_session():
 
182
  curr_use_case = use_case[app_mode].split(".")[0]
183
  st.markdown("<h5 style='text-align: center;'>Compare popular/state-of-the-art models for tasks using sentence embeddings</h5>", unsafe_allow_html=True)
184
  st.markdown(f"<div style='color: #4f4f4f; text-align: left'>Use cases for sentence embeddings<br/>&nbsp;&nbsp;&nbsp;•&nbsp;&nbsp;<a href=\'{use_case_url['1']}\' target='_blank'>{use_case['1']}</a><br/>&nbsp;&nbsp;&nbsp;•&nbsp;&nbsp;{use_case['2']}<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)
185
+ st.markdown(f"<div style='color: #9f9f9f; text-align: right'>views:&nbsp;{get_views('init')}</div>", unsafe_allow_html=True)
186
 
187
 
188
  try: