Spaces:
Running
Running
initial upload
Browse files- .gitignore +1 -0
- README.md +4 -5
- app.py +61 -0
- requirements.txt +2 -0
.gitignore
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
flagged/
|
README.md
CHANGED
|
@@ -1,14 +1,13 @@
|
|
| 1 |
---
|
| 2 |
title: ImBD
|
| 3 |
-
emoji:
|
| 4 |
-
colorFrom:
|
| 5 |
colorTo: purple
|
| 6 |
sdk: gradio
|
| 7 |
-
sdk_version: 5.
|
| 8 |
app_file: app.py
|
| 9 |
pinned: false
|
| 10 |
license: apache-2.0
|
| 11 |
-
short_description: An online demo for Imitate Before Detect
|
| 12 |
---
|
| 13 |
|
| 14 |
-
|
|
|
|
| 1 |
---
|
| 2 |
title: ImBD
|
| 3 |
+
emoji: 💬
|
| 4 |
+
colorFrom: yellow
|
| 5 |
colorTo: purple
|
| 6 |
sdk: gradio
|
| 7 |
+
sdk_version: 5.0.1
|
| 8 |
app_file: app.py
|
| 9 |
pinned: false
|
| 10 |
license: apache-2.0
|
|
|
|
| 11 |
---
|
| 12 |
|
| 13 |
+
An demo detector using [Gradio](https://gradio.app).
|
app.py
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import requests
|
| 3 |
+
import os
|
| 4 |
+
|
| 5 |
+
class Client:
|
| 6 |
+
def __init__(self):
|
| 7 |
+
self.url = os.getenv("SERVICE_IP")
|
| 8 |
+
self.headers = {
|
| 9 |
+
"x-api-key": os.getenv("APIKEY")
|
| 10 |
+
}
|
| 11 |
+
|
| 12 |
+
def detect(self, document):
|
| 13 |
+
data = {
|
| 14 |
+
"document": document,
|
| 15 |
+
"version": "no-version",
|
| 16 |
+
"multilingual": False
|
| 17 |
+
}
|
| 18 |
+
if len(document) > 3000:
|
| 19 |
+
return "Document is too long for this demo"
|
| 20 |
+
response = requests.post(self.url, json=data, headers=self.headers)
|
| 21 |
+
response = response.json()
|
| 22 |
+
documents = response.get("documents")
|
| 23 |
+
res = ""
|
| 24 |
+
len_ai=0
|
| 25 |
+
len_human=0
|
| 26 |
+
for doc in documents:
|
| 27 |
+
if "AI" in doc["classification"]:
|
| 28 |
+
len_ai += len(doc["original_paragraph"])
|
| 29 |
+
res += f'<span style="color:red;">{doc["original_paragraph"]}</span>'
|
| 30 |
+
else:
|
| 31 |
+
len_human += len(doc["original_paragraph"])
|
| 32 |
+
res += f'<span style="color:green;">{doc["original_paragraph"]}</span>'
|
| 33 |
+
|
| 34 |
+
res += f"<br><br>The above text has a probability of {len_ai/(len_ai+len_human)*100:.2f}% to be AI."
|
| 35 |
+
return res
|
| 36 |
+
|
| 37 |
+
client = Client()
|
| 38 |
+
|
| 39 |
+
def respond(
|
| 40 |
+
message,
|
| 41 |
+
):
|
| 42 |
+
return client.detect(message)
|
| 43 |
+
|
| 44 |
+
description = '<span style="font-size: 30px;">🤖 Demo for [ImBD](https://github.com/Jiaqi-Chen-00/ImBD) <br></span>'\
|
| 45 |
+
'<span style="font-size: 18px;">We slice the input text into segments of 300 characters each, ' \
|
| 46 |
+
'supporting a maximum text length of 3000 characters.<br>'\
|
| 47 |
+
'The result for each segment is indicated by green for human and red for AI on the right.</span>'
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
demo = gr.Interface(
|
| 51 |
+
fn=respond,
|
| 52 |
+
inputs=[
|
| 53 |
+
gr.Textbox(label="Input Message"),
|
| 54 |
+
],
|
| 55 |
+
outputs="html",
|
| 56 |
+
description=description
|
| 57 |
+
)
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
if __name__ == "__main__":
|
| 61 |
+
demo.launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
huggingface_hub==0.25.2
|
| 2 |
+
requests
|