Spaces:
Runtime error
Runtime error
Updated GUI
Browse files
app.py
CHANGED
|
@@ -1,8 +1,11 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline, AutoTokenizer, AutoModelForSequenceClassification
|
| 3 |
|
|
|
|
| 4 |
models = ["bert-base-uncased", "roberta-base"]
|
| 5 |
-
|
|
|
|
|
|
|
| 6 |
"vedantgaur/GPTOutputs-MWP - AI Data Only",
|
| 7 |
"vedantgaur/GPTOutputs-MWP - Human Data Only",
|
| 8 |
"vedantgaur/GPTOutputs-MWP - Both AI and Human Data",
|
|
@@ -22,6 +25,7 @@ model_mapping = {
|
|
| 22 |
("roberta-base", "dmitva/human_ai_generated_text - Both AI and Human Data"): "SkwarczynskiP/roberta-base-finetuned-dmitva-AI-and-human-generated"
|
| 23 |
}
|
| 24 |
|
|
|
|
| 25 |
def detect_ai_generated_text(model: str, dataset: str, text: str) -> str:
|
| 26 |
# Get the fine-tuned model using mapping
|
| 27 |
finetuned_model = model_mapping.get((model, dataset))
|
|
@@ -33,7 +37,21 @@ def detect_ai_generated_text(model: str, dataset: str, text: str) -> str:
|
|
| 33 |
# Classify the input based on the fine-tuned model
|
| 34 |
classifier = pipeline('text-classification', model=model, tokenizer=tokenizer)
|
| 35 |
result = classifier(text)
|
| 36 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
|
| 38 |
interface = gr.Interface(
|
| 39 |
fn=detect_ai_generated_text,
|
|
@@ -42,7 +60,9 @@ interface = gr.Interface(
|
|
| 42 |
gr.Dropdown(choices=datasets, label="Dataset"),
|
| 43 |
gr.Textbox(lines=5, label="Input Text")
|
| 44 |
],
|
| 45 |
-
outputs=gr.Textbox(label="Output")
|
|
|
|
|
|
|
| 46 |
)
|
| 47 |
|
| 48 |
if __name__ == "__main__":
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline, AutoTokenizer, AutoModelForSequenceClassification
|
| 3 |
|
| 4 |
+
# Models included within the interface
|
| 5 |
models = ["bert-base-uncased", "roberta-base"]
|
| 6 |
+
|
| 7 |
+
# Datasets included within the interface
|
| 8 |
+
datasets = ["None",
|
| 9 |
"vedantgaur/GPTOutputs-MWP - AI Data Only",
|
| 10 |
"vedantgaur/GPTOutputs-MWP - Human Data Only",
|
| 11 |
"vedantgaur/GPTOutputs-MWP - Both AI and Human Data",
|
|
|
|
| 25 |
("roberta-base", "dmitva/human_ai_generated_text - Both AI and Human Data"): "SkwarczynskiP/roberta-base-finetuned-dmitva-AI-and-human-generated"
|
| 26 |
}
|
| 27 |
|
| 28 |
+
|
| 29 |
def detect_ai_generated_text(model: str, dataset: str, text: str) -> str:
|
| 30 |
# Get the fine-tuned model using mapping
|
| 31 |
finetuned_model = model_mapping.get((model, dataset))
|
|
|
|
| 37 |
# Classify the input based on the fine-tuned model
|
| 38 |
classifier = pipeline('text-classification', model=model, tokenizer=tokenizer)
|
| 39 |
result = classifier(text)
|
| 40 |
+
|
| 41 |
+
# Get the label and score
|
| 42 |
+
label = "AI-generated" if result[0]['label'] == 'LABEL_1' else "Human-written"
|
| 43 |
+
score = result[0]['score']
|
| 44 |
+
|
| 45 |
+
return f"{label} with confidence {score * 100:.2f}%"
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
# Examples included within the interface
|
| 49 |
+
examples = [
|
| 50 |
+
["AI Generated", ""],
|
| 51 |
+
["Human Written", ""],
|
| 52 |
+
["AI Generated", ""],
|
| 53 |
+
["Human Written", ""]
|
| 54 |
+
]
|
| 55 |
|
| 56 |
interface = gr.Interface(
|
| 57 |
fn=detect_ai_generated_text,
|
|
|
|
| 60 |
gr.Dropdown(choices=datasets, label="Dataset"),
|
| 61 |
gr.Textbox(lines=5, label="Input Text")
|
| 62 |
],
|
| 63 |
+
outputs=gr.Textbox(label="Output"),
|
| 64 |
+
examples=examples,
|
| 65 |
+
title="AI Generated Text Detection",
|
| 66 |
)
|
| 67 |
|
| 68 |
if __name__ == "__main__":
|