Spaces:
Runtime error
Runtime error
Adds demo
Browse files- app.py +37 -0
- requirements.txt +3 -0
app.py
ADDED
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
|
3 |
+
from transformers import pipeline
|
4 |
+
|
5 |
+
pipe = pipeline(model="fmops/ai-traffic-classifier")
|
6 |
+
id2label = {
|
7 |
+
'LABEL_0': 'not ai traffic',
|
8 |
+
'LABEL_1': 'suspected ai traffic'
|
9 |
+
}
|
10 |
+
|
11 |
+
|
12 |
+
def predict(path, method, content):
|
13 |
+
prompt = f"""
|
14 |
+
path: {path}
|
15 |
+
method: {method}
|
16 |
+
content: {content}
|
17 |
+
"""
|
18 |
+
return {id2label[x['label']]: x['score'] for x in pipe(prompt)}
|
19 |
+
|
20 |
+
with gr.Blocks() as demo:
|
21 |
+
gr.Markdown("""
|
22 |
+
# AI Traffic Classifier
|
23 |
+
|
24 |
+
This is a demo of the AI traffic classifier.
|
25 |
+
""")
|
26 |
+
iface = gr.Interface(
|
27 |
+
fn=predict,
|
28 |
+
inputs=["text", "text", "text"],
|
29 |
+
examples=[
|
30 |
+
["/login", "POST", ""],
|
31 |
+
["/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}"""],
|
32 |
+
["/api/chat", "POST", """{"text":"How are you aware of GPT-3? There must have been some data leakage..."}"""],
|
33 |
+
],
|
34 |
+
outputs="label",
|
35 |
+
)
|
36 |
+
|
37 |
+
demo.launch()
|
requirements.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
transformers
|
2 |
+
torch
|
3 |
+
gradio
|