Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
Fix query params for spaces
Browse files- detector/server.py +11 -6
detector/server.py
CHANGED
@@ -7,13 +7,17 @@ from transformers import RobertaForSequenceClassification, RobertaTokenizer
|
|
7 |
import json
|
8 |
import fire
|
9 |
import torch
|
10 |
-
|
11 |
-
|
12 |
|
13 |
model: RobertaForSequenceClassification = None
|
14 |
tokenizer: RobertaTokenizer = None
|
15 |
device: str = None
|
16 |
|
|
|
|
|
|
|
|
|
17 |
def log(*args):
|
18 |
print(f"[{os.environ.get('RANK', '')}]", *args, file=sys.stderr)
|
19 |
|
@@ -45,10 +49,11 @@ class RequestHandler(SimpleHTTPRequestHandler):
|
|
45 |
self.wfile.write(json.dumps({"error": str(e)}).encode('utf-8'))
|
46 |
|
47 |
def do_GET(self):
|
48 |
-
|
49 |
-
|
|
|
50 |
|
51 |
-
if
|
52 |
self.begin_content('text/html')
|
53 |
|
54 |
html = os.path.join(os.path.dirname(__file__), 'index.html')
|
@@ -57,7 +62,7 @@ class RequestHandler(SimpleHTTPRequestHandler):
|
|
57 |
|
58 |
self.begin_content('application/json;charset=UTF-8')
|
59 |
|
60 |
-
all_tokens, used_tokens, fake, real = self.infer(
|
61 |
|
62 |
self.wfile.write(json.dumps(dict(
|
63 |
all_tokens=all_tokens,
|
|
|
7 |
import json
|
8 |
import fire
|
9 |
import torch
|
10 |
+
import re
|
11 |
+
from urllib.parse import urlparse, unquote, parse_qs, urlencode
|
12 |
|
13 |
model: RobertaForSequenceClassification = None
|
14 |
tokenizer: RobertaTokenizer = None
|
15 |
device: str = None
|
16 |
|
17 |
+
# Remove spaces query params from query
|
18 |
+
regex = r"__theme=(.+)"
|
19 |
+
|
20 |
+
|
21 |
def log(*args):
|
22 |
print(f"[{os.environ.get('RANK', '')}]", *args, file=sys.stderr)
|
23 |
|
|
|
49 |
self.wfile.write(json.dumps({"error": str(e)}).encode('utf-8'))
|
50 |
|
51 |
def do_GET(self):
|
52 |
+
query = urlparse(self.path).query
|
53 |
+
query = re.sub(regex, "", query, 0, re.MULTILINE)
|
54 |
+
query = unquote(query)
|
55 |
|
56 |
+
if not query:
|
57 |
self.begin_content('text/html')
|
58 |
|
59 |
html = os.path.join(os.path.dirname(__file__), 'index.html')
|
|
|
62 |
|
63 |
self.begin_content('application/json;charset=UTF-8')
|
64 |
|
65 |
+
all_tokens, used_tokens, fake, real = self.infer(query)
|
66 |
|
67 |
self.wfile.write(json.dumps(dict(
|
68 |
all_tokens=all_tokens,
|