Upload 3 files
Browse files- README.md +3 -3
- app.py +47 -0
- requirements.txt +2 -0
README.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
| 1 |
---
|
| 2 |
title: KInIT Multilingual Machine-Generated Text Detector
|
| 3 |
-
emoji:
|
| 4 |
-
colorFrom:
|
| 5 |
-
colorTo:
|
| 6 |
sdk: gradio
|
| 7 |
sdk_version: 4.44.0
|
| 8 |
app_file: app.py
|
|
|
|
| 1 |
---
|
| 2 |
title: KInIT Multilingual Machine-Generated Text Detector
|
| 3 |
+
emoji: ⚡
|
| 4 |
+
colorFrom: indigo
|
| 5 |
+
colorTo: pink
|
| 6 |
sdk: gradio
|
| 7 |
sdk_version: 4.44.0
|
| 8 |
app_file: app.py
|
app.py
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import gradio as gr
|
| 3 |
+
import requests
|
| 4 |
+
import json
|
| 5 |
+
from urllib.parse import quote
|
| 6 |
+
|
| 7 |
+
auth_token = os.environ.get("kinit_mgt_access_token")
|
| 8 |
+
share = os.environ.get("GRADIO_SHARE")
|
| 9 |
+
|
| 10 |
+
def get_api_response(text):
|
| 11 |
+
url = "https://mgt-detector.model.kinit.sk/prod/?q=" + quote(text)
|
| 12 |
+
payload = {}
|
| 13 |
+
headers = {
|
| 14 |
+
'x-api-key': auth_token
|
| 15 |
+
}
|
| 16 |
+
response = requests.request("GET", url, headers=headers, data=payload)
|
| 17 |
+
response = json.loads(response.text)
|
| 18 |
+
return response
|
| 19 |
+
|
| 20 |
+
def predict(text):
|
| 21 |
+
#return 'machine', 1.0
|
| 22 |
+
res = get_api_response(text)
|
| 23 |
+
if 'pred' not in res.keys():
|
| 24 |
+
return "Waiting for the server startup, try again!", "Waiting for the server startup, try again!"
|
| 25 |
+
pred = "Very likely human-written"
|
| 26 |
+
if res['score'] > 0.05: pred = "Likely human-written"
|
| 27 |
+
if res['score'] > 0.5: pred = "Likely machine-generated"
|
| 28 |
+
if res['score'] > 0.95: pred = "Very likely machine-generated"
|
| 29 |
+
return pred,res['score']
|
| 30 |
+
|
| 31 |
+
with gr.Blocks(analytics_enabled=False) as demo:
|
| 32 |
+
gr.Markdown("""
|
| 33 |
+
## KInIT Multilingual Machine-Generated Text Detector
|
| 34 |
+
Trained on [MULTITuDE](https://aclanthology.org/2023.emnlp-main.616/) (news articles) and [MultiSocial](https://arxiv.org/abs/2406.12549) (social media texts) texts in 22 languages.
|
| 35 |
+
""")
|
| 36 |
+
gr.Markdown("""
|
| 37 |
+
**Disclaimer: The detector is based on AI transformer model and is NOT 100% accurate! Usage is intended for research purpose only, as an indicator. Do not use it for direct decision making!**""")
|
| 38 |
+
gr.Markdown("""To generate examplar text by a large language model, you can use [HuggingFace Chat](https://huggingface.co/chat/).""")
|
| 39 |
+
t1 = gr.Textbox(lines=10, label='Text',value="Put your text (in any language) in here to try out our multilingual machine-generated text detector.")
|
| 40 |
+
button1 = gr.Button("Run detection")
|
| 41 |
+
label1 = gr.Textbox(lines=1, label='Result')
|
| 42 |
+
score1 = gr.Textbox(lines=1, label='Probability (closer to 0 means higher probability of text being written by a human, closer to 1 means higher probability of text being generated by an AI model)')
|
| 43 |
+
|
| 44 |
+
button1.click(predict, inputs=[t1], outputs=[label1,score1], api_name=False)
|
| 45 |
+
|
| 46 |
+
if __name__ == "__main__":
|
| 47 |
+
demo.launch(show_api=False, share=share)
|
requirements.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio
|
| 2 |
+
requests
|