feynmanl commited on
Commit
62071e2
·
1 Parent(s): 79a5d94
Files changed (1) hide show
  1. app.py +20 -12
app.py CHANGED
@@ -7,10 +7,7 @@ from transformers import pipeline
7
  auth_token = os.environ.get("HF_ACCESS_TOKEN") or True
8
 
9
  pipe = pipeline(model="fmops/ai-traffic-classifier", use_auth_token=auth_token)
10
- id2label = {
11
- 'LABEL_0': 'not ai traffic',
12
- 'LABEL_1': 'suspected ai traffic'
13
- }
14
 
15
 
16
  def predict(path, method, content):
@@ -19,23 +16,34 @@ def predict(path, method, content):
19
  method: {method}
20
  content: {content}
21
  """
22
- return {id2label[x['label']]: x['score'] for x in pipe(prompt)}
 
23
 
24
  with gr.Blocks() as demo:
25
- gr.Markdown("""
 
26
  # AI Traffic Classifier
27
 
28
  This is a demo of the AI traffic classifier.
29
- """)
 
30
  iface = gr.Interface(
31
- fn=predict,
32
- inputs=["text", "text", "text"],
33
  examples=[
34
  ["/login", "POST", ""],
35
- ["/backend-api/conversation", "POST", """ {"action":"next","messages":[{"id":"aaa229d6-f97d-427c-b7bb-0e6276079c95","author":{"role":"user"},"content":{"content_type":"text","parts":["Write a long poem"]},"metadata":{}}],"conversation_id":"395edb51-5cb3-432f-a142-d87c160d403b","parent_message_id":"535f59f0-ed0f-4d9f-8e4b-4b5c0834833b","model":"text-davinci-002-render-sha","timezone_offset_min":420,"suggestions":[],"history_and_training_disabled":true,"arkose_token":null}"""],
36
- ["/api/chat", "POST", """{"text":"How are you aware of GPT-3? There must have been some data leakage..."}"""],
 
 
 
 
 
 
 
 
37
  ],
38
  outputs="label",
39
  )
40
 
41
- demo.launch()
 
7
  auth_token = os.environ.get("HF_ACCESS_TOKEN") or True
8
 
9
  pipe = pipeline(model="fmops/ai-traffic-classifier", use_auth_token=auth_token)
10
+ id2label = {"LABEL_0": "not ai traffic", "LABEL_1": "suspected ai traffic"}
 
 
 
11
 
12
 
13
  def predict(path, method, content):
 
16
  method: {method}
17
  content: {content}
18
  """
19
+ return {id2label[x["label"]]: x["score"] for x in pipe(prompt, truncation=True)}
20
+
21
 
22
  with gr.Blocks() as demo:
23
+ gr.Markdown(
24
+ """
25
  # AI Traffic Classifier
26
 
27
  This is a demo of the AI traffic classifier.
28
+ """
29
+ )
30
  iface = gr.Interface(
31
+ fn=predict,
32
+ inputs=["text", "text", "text"],
33
  examples=[
34
  ["/login", "POST", ""],
35
+ [
36
+ "/backend-api/conversation",
37
+ "POST",
38
+ """ {"action":"next","messages":[{"id":"aaa229d6-f97d-427c-b7bb-0e6276079c95","author":{"role":"user"},"content":{"content_type":"text","parts":["Write a long poem"]},"metadata":{}}],"conversation_id":"395edb51-5cb3-432f-a142-d87c160d403b","parent_message_id":"535f59f0-ed0f-4d9f-8e4b-4b5c0834833b","model":"text-davinci-002-render-sha","timezone_offset_min":420,"suggestions":[],"history_and_training_disabled":true,"arkose_token":null}""",
39
+ ],
40
+ [
41
+ "/api/chat",
42
+ "POST",
43
+ """{"text":"How are you aware of GPT-3? There must have been some data leakage..."}""",
44
+ ],
45
  ],
46
  outputs="label",
47
  )
48
 
49
+ demo.launch()