Spaces:
Sleeping
Sleeping
add app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import gradio.components as grc
|
| 3 |
+
# from wmdetection.models import get_watermarks_detection_model
|
| 4 |
+
# from wmdetection.pipelines.predictor import WatermarksPredictor
|
| 5 |
+
import os, glob
|
| 6 |
+
import spaces
|
| 7 |
+
from transformers import AutoModelForSequenceClassification, AutoTokenizer
|
| 8 |
+
import torch
|
| 9 |
+
model_name = 'https://huggingface.co/hyunseoki/ReMoDetect-deberta'
|
| 10 |
+
|
| 11 |
+
THESHOLD=4.0
|
| 12 |
+
predictor = AutoModelForSequenceClassification.from_pretrained(model_name)
|
| 13 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 14 |
+
|
| 15 |
+
@spaces.GPU
|
| 16 |
+
def predict(text):
|
| 17 |
+
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 18 |
+
predictor.to(device)
|
| 19 |
+
tokenized = tokenizer(text, return_tensors='pt', truncation=True, max_length=512).to(device)
|
| 20 |
+
result = predictor(**tokenized).logits[0].cpu().detach().item()
|
| 21 |
+
AI_score = round(torch.sigmoid(torch.tensor(result-THESHOLD)*2).item(),2)
|
| 22 |
+
return f'{AI_score*100} %', f'{round(result,2)}'
|
| 23 |
+
|
| 24 |
+
iface = gr.Interface(
|
| 25 |
+
fn=predict,
|
| 26 |
+
title="ReMoDetect: Reward Model for LLM Generated Text Detection",
|
| 27 |
+
description="The continuously finetuned reward model so that can classify LLM generated text from human writen text.",
|
| 28 |
+
inputs=grc.Textbox(label='INPUT', placeholder="Type here..."),
|
| 29 |
+
# examples=examples,
|
| 30 |
+
outputs=[grc.Textbox(label="AI likelihood"), grc.Textbox(label="Raw score")],
|
| 31 |
+
)
|
| 32 |
+
iface.launch(share=True)
|