| | import os |
| | import gradio as gr |
| | import requests |
| | import json |
| | from urllib.parse import quote |
| |
|
| | auth_token = os.environ.get("kinit_mgt_access_token") |
| | share = os.environ.get("GRADIO_SHARE") |
| |
|
| | def get_api_response(text): |
| | url = "https://mgt-detector.model.kinit.sk/prod/?q=" + quote(text) |
| | payload = {} |
| | headers = { |
| | 'x-api-key': auth_token |
| | } |
| | response = requests.request("GET", url, headers=headers, data=payload) |
| | response = json.loads(response.text) |
| | return response |
| |
|
| | def predict(text): |
| | |
| | res = get_api_response(text) |
| | if 'pred' not in res.keys(): |
| | return "Waiting for the server startup (up to 1 min for the first request), try again!", "Waiting for the server startup (up to 1 min for the first request), try again!" |
| | pred = "Very likely human-written" |
| | if res['score'] > 0.05: pred = "Likely human-written" |
| | if res['score'] > 0.5: pred = "Likely machine-generated" |
| | if res['score'] > 0.95: pred = "Very likely machine-generated" |
| | return pred,res['score'] |
| |
|
| | with gr.Blocks(analytics_enabled=False) as demo: |
| | gr.Markdown(""" |
| | ## DEMO: KInIT Multilingual Machine-Generated Text Detector |
| | 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. |
| | """) |
| | gr.Markdown(""" |
| | **Disclaimer: This is a DEMO for showcase, not the final tool. 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!**""") |
| | gr.Markdown("""To generate exemplar text by a large language model, you can use [HuggingFace Chat](https://huggingface.co/chat/).""") |
| | 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.") |
| | button1 = gr.Button("Run detection") |
| | label1 = gr.Textbox(lines=1, label='Result') |
| | 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)') |
| | |
| | button1.click(predict, inputs=[t1], outputs=[label1,score1], api_name=False) |
| |
|
| | if __name__ == "__main__": |
| | demo.launch(show_api=False, share=share) |