Spaces:
Runtime error
Runtime error
Enhanced visuals
Browse files
app.py
CHANGED
|
@@ -28,10 +28,10 @@ model_mapping = {
|
|
| 28 |
|
| 29 |
# Example text included within the interface
|
| 30 |
exampleText = [
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
]
|
| 36 |
|
| 37 |
# Example models and datasets included within the interface
|
|
@@ -47,7 +47,7 @@ exampleDatasets = ["No Dataset Finetuning",
|
|
| 47 |
examples = [[random.choice(exampleModels), random.choice(exampleDatasets), random.choice(exampleText)] for example in exampleText]
|
| 48 |
|
| 49 |
|
| 50 |
-
def detect_ai_generated_text(model: str, dataset: str, text: str) ->
|
| 51 |
# Get the fine-tuned model using mapping
|
| 52 |
finetuned_model = model_mapping.get((model, dataset))
|
| 53 |
|
|
@@ -63,7 +63,13 @@ def detect_ai_generated_text(model: str, dataset: str, text: str) -> str:
|
|
| 63 |
label = "AI-generated" if result[0]['label'] == 'LABEL_1' else "Human-written"
|
| 64 |
score = result[0]['score']
|
| 65 |
|
| 66 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 67 |
|
| 68 |
|
| 69 |
interface = gr.Interface(
|
|
@@ -73,7 +79,11 @@ interface = gr.Interface(
|
|
| 73 |
gr.Dropdown(choices=datasets, label="Dataset"),
|
| 74 |
gr.Textbox(lines=5, label="Input Text")
|
| 75 |
],
|
| 76 |
-
outputs=
|
|
|
|
|
|
|
|
|
|
|
|
|
| 77 |
examples=examples,
|
| 78 |
title="AI Generated Text Detection"
|
| 79 |
)
|
|
|
|
| 28 |
|
| 29 |
# Example text included within the interface
|
| 30 |
exampleText = [
|
| 31 |
+
"ex1",
|
| 32 |
+
"ex2",
|
| 33 |
+
"ex3",
|
| 34 |
+
"ex4"
|
| 35 |
]
|
| 36 |
|
| 37 |
# Example models and datasets included within the interface
|
|
|
|
| 47 |
examples = [[random.choice(exampleModels), random.choice(exampleDatasets), random.choice(exampleText)] for example in exampleText]
|
| 48 |
|
| 49 |
|
| 50 |
+
def detect_ai_generated_text(model: str, dataset: str, text: str) -> dict:
|
| 51 |
# Get the fine-tuned model using mapping
|
| 52 |
finetuned_model = model_mapping.get((model, dataset))
|
| 53 |
|
|
|
|
| 63 |
label = "AI-generated" if result[0]['label'] == 'LABEL_1' else "Human-written"
|
| 64 |
score = result[0]['score']
|
| 65 |
|
| 66 |
+
# Create HTML for the colored bars
|
| 67 |
+
ai_score = score if label == "AI-generated" else 1 - score
|
| 68 |
+
human_score = 1 - ai_score
|
| 69 |
+
ai_bar = f'<div style="background-color: red; width: {ai_score * 100}%; height: 20px;"></div>'
|
| 70 |
+
human_bar = f'<div style="background-color: blue; width: {human_score * 100}%; height: 20px;"></div>'
|
| 71 |
+
|
| 72 |
+
return {"label": f"{label} with confidence {score * 100:.2f}%", "ai_bar": ai_bar, "human_bar": human_bar}
|
| 73 |
|
| 74 |
|
| 75 |
interface = gr.Interface(
|
|
|
|
| 79 |
gr.Dropdown(choices=datasets, label="Dataset"),
|
| 80 |
gr.Textbox(lines=5, label="Input Text")
|
| 81 |
],
|
| 82 |
+
outputs=[
|
| 83 |
+
gr.Label(label="Output"),
|
| 84 |
+
gr.HTML(label="AI-generated"),
|
| 85 |
+
gr.HTML(label="Human-written")
|
| 86 |
+
],
|
| 87 |
examples=examples,
|
| 88 |
title="AI Generated Text Detection"
|
| 89 |
)
|