juliensimon HF staff commited on
Commit
4156f8b
1 Parent(s): 960a747

First version

Browse files
Files changed (2) hide show
  1. code/predict.py +13 -0
  2. code/predict_infinity.py +15 -0
code/predict.py ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import time
2
+ from transformers import pipeline
3
+
4
+ pipeline = pipeline("sentiment-analysis", model="juliensimon/autonlp-imdb-demo-hf-16622767", use_auth_token=True)
5
+
6
+ data = "Dune is something rarely seen anymore – it’s an epic."
7
+
8
+ tick=time.time_ns()
9
+ for i in range(0,100):
10
+ response=pipeline(data)
11
+ tock=time.time_ns()
12
+
13
+ print("%.2fms" % ((tock-tick)/1000/1000/100))
code/predict_infinity.py ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import requests as r
2
+ import time
3
+
4
+ input_data = { "inputs": "Dune is something rarely seen anymore – it’s an epic."}
5
+
6
+ url = "http://localhost:8080/predict"
7
+
8
+ sum=0
9
+ for i in range(0,1000):
10
+ response = r.post(url, json=input_data)
11
+ resp_time = response.headers["x-compute-time"]
12
+ sum+=float(resp_time)
13
+
14
+ sum/=1000
15
+ print(f"{round(float(sum),6)*1000}ms")