cetinca commited on
Commit
72f4be8
·
verified ·
1 Parent(s): 17f6802

Created bash script to test

Browse files
Files changed (3) hide show
  1. .gitignore +1 -0
  2. test_api.py +2 -2
  3. test_api.sh +61 -0
.gitignore CHANGED
@@ -99,3 +99,4 @@ docs/**/*.html
99
  **/*secret*
100
  **/*private*
101
  /call_history.csv
 
 
99
  **/*secret*
100
  **/*private*
101
  /call_history.csv
102
+ /call_history.txt
test_api.py CHANGED
@@ -11,8 +11,8 @@ NUMBER_OF_CALLS = 20
11
 
12
  headers = {"Content-Type": "application/json; charset=utf-8"}
13
 
14
- # base_url = "https://tangibleai-mathtext.hf.space/run/{endpoint}"
15
- base_url = "http://localhost:7860/run/{endpoint}"
16
 
17
  data_list_1 = {
18
  "endpoint": "text2int",
 
11
 
12
  headers = {"Content-Type": "application/json; charset=utf-8"}
13
 
14
+ base_url = "https://tangibleai-mathtext.hf.space/run/{endpoint}"
15
+ # base_url = "http://localhost:7860/run/{endpoint}"
16
 
17
  data_list_1 = {
18
  "endpoint": "text2int",
test_api.sh ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #! /bin/env bash
2
+
3
+ data_list_1() {
4
+ responses=(
5
+ "one hundred forty five"
6
+ "twenty thousand nine hundred fifty"
7
+ "one hundred forty five"
8
+ "nine hundred eighty three"
9
+ "five million"
10
+ )
11
+ echo "${responses[$1]}"
12
+ }
13
+
14
+ data_list_2() {
15
+ responses=(
16
+ "Totally agree"
17
+ "I like it"
18
+ "No more"
19
+ "I am not sure"
20
+ "Never"
21
+ )
22
+ echo "${responses[$1]}"
23
+ }
24
+
25
+ text2int="https://tangibleai-mathtext.hf.space/run/text2int"
26
+ text2intpreprocessed="https://tangibleai-mathtext.hf.space/run/text2int-preprocessed"
27
+ sentimentanalysis="https://tangibleai-mathtext.hf.space/run/sentiment-analysis"
28
+
29
+ test_endpoint() {
30
+ start_=$(date +%s.%N)
31
+ response=$(curl --silent -X POST "$1" -H 'Content-Type: application/json' -d "$2")
32
+ end_=$(date +%s.%N)
33
+ diff=$(echo "$end_ - $start_" | bc)
34
+ printf " endpoint:%s\n data:%s delay:%s:\n %s\n" "$1" "$2" "$diff" "$response"
35
+ }
36
+
37
+ echo "start: $(date)"
38
+
39
+ for i in {1..20}; do
40
+ random_value=$((RANDOM % 5))
41
+ text=$(data_list_1 $random_value)
42
+ data='{"data": ["'$text'"]}'
43
+ test_endpoint "$text2int" "$data" >>call_history.txt &
44
+ done
45
+
46
+ for i in {1..20}; do
47
+ random_value=$((RANDOM % 5))
48
+ text=$(data_list_1 $random_value)
49
+ data='{"data": ["'$text'"]}'
50
+ test_endpoint "$text2intpreprocessed" "$data" >>call_history.txt &
51
+ done
52
+
53
+ for i in {1..20}; do
54
+ random_value=$((RANDOM % 5))
55
+ text=$(data_list_2 $random_value)
56
+ data='{"data": ["'$text'"]}'
57
+ test_endpoint "$sentimentanalysis" "$data" >>call_history.txt &
58
+ done
59
+
60
+ wait
61
+ echo "end: $(date)"