罗俊辉 10 місяців тому
батько
коміт
56d93108c8
2 змінених файлів з 42 додано та 35 видалено
  1. 21 12
      test/nlp_dev.py
  2. 21 23
      test/test.py

+ 21 - 12
test/nlp_dev.py

@@ -5,7 +5,9 @@ import json
 import requests
 import time
 
-url = "http://47.98.154.124:6060/nlp"
+from concurrent.futures.thread import ThreadPoolExecutor
+
+
 
 list_data = {
     "text_list_a": ["凯旋", "毛泽东", "周恩来"],
@@ -32,11 +34,11 @@ body3 = {
 
 body4 = {
     "data": {
-                    "text_list_a": ["牛逼", "毛泽东", "王一博"],
-                    "text_list_b": ["肖战", "邓小平", "绝了", "蒋介石"],
-                    "score_list_b": [100, 1000, 500, 40],
-                    "symbol": 1,
-                },
+        "text_list_a": ["牛逼", "毛泽东", "王一博"],
+        "text_list_b": ["肖战", "邓小平", "绝了", "蒋介石"],
+        "score_list_b": [100, 1000, 500, 40],
+        "symbol": 1,
+    },
     "function": "similarities_cross_avg"
 }
 
@@ -45,10 +47,17 @@ body5 = {
     "function": "similarities_cross_mean"
 }
 
-headers = {"Content-Type": "application/json"}
 
-a = time.time()
-response = requests.post(url=url, headers=headers, json=body1)
-b = time.time()
-print(json.dumps(response.json(), ensure_ascii=False, indent=4))
-print(b - a)
+def test_request(url):
+    headers = {"Content-Type": "application/json"}
+    a = time.time()
+    response = requests.post(url=url, headers=headers, json=body5)
+    b = time.time()
+    print(json.dumps(response.json(), ensure_ascii=False, indent=4))
+    print(b - a)
+
+
+url_list = ["http://47.98.154.124:6060/nlp"] * 10
+
+with ThreadPoolExecutor(max_workers=3) as Pool:
+    Pool.map(test_request, url_list)

+ 21 - 23
test/test.py

@@ -1,23 +1,21 @@
-"""
-@author: luojunhui
-"""
-import json
-
-
-path = "test.json"
-
-
-obj = {
-    "1": "1",
-    "2": "2"
-}
-
-with open(path, "w", encoding="utf-8") as f:
-    f.write(json.dumps(obj, ensure_ascii=False, indent=4) + "\n")
-
-
-with open(path, encoding="utf-8") as f:
-    data = json.loads(f.read())
-
-print(data)
-print(type(data))
+import requests
+
+
+def article_safe(title):
+    """
+    判断文章是否安全
+    """
+    url = "http://192.168.100.31:8177/sensitive/is_sensitive"
+    body = {
+        "text": title
+    }
+    response = requests.post(
+        url=url,
+        json=body,
+        headers={"Content-Type": "application/json"}
+    )
+    return response.json()['is_sensitive']
+
+
+res = article_safe("11岁女孩裤子沾了血迹,同学们笑话她,爸爸一番话,让人敬佩")
+print(res)