dylanplummer commited on
Commit
d192993
·
1 Parent(s): 98fee40

add simple token auth

Browse files
Files changed (2) hide show
  1. app.py +12 -6
  2. requirements.txt +1 -0
app.py CHANGED
@@ -13,6 +13,7 @@ import matplotlib.pyplot as plt
13
  from matplotlib.animation import FuncAnimation
14
  from scipy.signal import medfilt
15
  from functools import partial
 
16
  from tqdm import tqdm
17
  import pandas as pd
18
  import plotly.express as px
@@ -118,11 +119,15 @@ def confidence_analysis(periodicity, counts, frames, out_dir='confidence_animati
118
  plt.close(fig)
119
 
120
 
121
- def inference(x, count_only_api, img_size=192, seq_len=64, stride_length=32, stride_pad=3, batch_size=4, miss_threshold=0.85, median_pred_filter=True, center_crop=True, both_feet=True, api_call=False):
122
  print(x)
123
- api = HfApi(token=os.environ['DATASET_SECRET'])
124
- out_file = str(uuid.uuid1())
125
-
 
 
 
 
126
 
127
  cap = cv2.VideoCapture(x)
128
  length = int(cap.get(cv2.CAP_PROP_FRAME_COUNT))
@@ -319,6 +324,7 @@ with gr.Blocks() as demo:
319
  run_button = gr.Button(label="Run", elem_id='run-button', style=dict(full_width=False), scale=1)
320
  api_dummy_button = gr.Button(label="Run (No Viz)", elem_id='count-only', visible=False, scale=2)
321
  count_only = gr.Checkbox(label="Count Only", visible=False)
 
322
 
323
  with gr.Column(elem_id='output-video-container'):
324
  with gr.Row():
@@ -356,10 +362,10 @@ with gr.Blocks() as demo:
356
  inputs=[in_video],
357
  outputs=[out_text, out_plot, out_hist],
358
  fn=inference, cache_examples=os.getenv('SYSTEM') == 'spaces')
359
- demo_inference = partial(inference, count_only_api=False)
360
  run_button.click(demo_inference, [in_video], outputs=[out_text, out_plot, out_hist])
361
  api_inference = partial(inference, api_call=True)
362
- api_dummy_button.click(api_inference, [in_video, count_only], outputs=[period_length], api_name='inference')
363
 
364
 
365
  if __name__ == "__main__":
 
13
  from matplotlib.animation import FuncAnimation
14
  from scipy.signal import medfilt
15
  from functools import partial
16
+ from passlib.hash import pbkdf2_sha256
17
  from tqdm import tqdm
18
  import pandas as pd
19
  import plotly.express as px
 
119
  plt.close(fig)
120
 
121
 
122
+ def inference(x, count_only_api, api_key, img_size=192, seq_len=64, stride_length=32, stride_pad=3, batch_size=4, miss_threshold=0.85, median_pred_filter=True, center_crop=True, both_feet=True, api_call=False):
123
  print(x)
124
+ #api = HfApi(token=os.environ['DATASET_SECRET'])
125
+ #out_file = str(uuid.uuid1())
126
+ has_access = False
127
+ if api_call:
128
+ has_access = pbkdf2_sha256.verify(os.environ['DEV_API_TOKEN'], api_key)
129
+ if not has_access:
130
+ return "Invalid API Key"
131
 
132
  cap = cv2.VideoCapture(x)
133
  length = int(cap.get(cv2.CAP_PROP_FRAME_COUNT))
 
324
  run_button = gr.Button(label="Run", elem_id='run-button', style=dict(full_width=False), scale=1)
325
  api_dummy_button = gr.Button(label="Run (No Viz)", elem_id='count-only', visible=False, scale=2)
326
  count_only = gr.Checkbox(label="Count Only", visible=False)
327
+ api_token = gr.Textbox(label="API Key", elem_id='api-token', visible=False)
328
 
329
  with gr.Column(elem_id='output-video-container'):
330
  with gr.Row():
 
362
  inputs=[in_video],
363
  outputs=[out_text, out_plot, out_hist],
364
  fn=inference, cache_examples=os.getenv('SYSTEM') == 'spaces')
365
+ demo_inference = partial(inference, count_only_api=False, api_key=None)
366
  run_button.click(demo_inference, [in_video], outputs=[out_text, out_plot, out_hist])
367
  api_inference = partial(inference, api_call=True)
368
+ api_dummy_button.click(api_inference, [in_video, count_only, api_token], outputs=[period_length], api_name='inference')
369
 
370
 
371
  if __name__ == "__main__":
requirements.txt CHANGED
@@ -2,6 +2,7 @@ numpy
2
  pandas
3
  matplotlib
4
  plotly
 
5
  scipy
6
  --find-links https://download.pytorch.org/whl/torch_stable.html
7
  opencv-python-headless==4.7.0.68
 
2
  pandas
3
  matplotlib
4
  plotly
5
+ passlib
6
  scipy
7
  --find-links https://download.pytorch.org/whl/torch_stable.html
8
  opencv-python-headless==4.7.0.68