Spaces:
Runtime error
Runtime error
First GUI Update
Browse files
app.py
CHANGED
@@ -1,7 +1,39 @@
|
|
1 |
import gradio as gr
|
|
|
2 |
|
3 |
-
def greet(name):
|
4 |
-
return "Hello " + name + "!!"
|
5 |
|
6 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
iface.launch()
|
|
|
1 |
import gradio as gr
|
2 |
+
from transformers import pipeline, AutoTokenizer, AutoModelForSequenceClassification
|
3 |
|
|
|
|
|
4 |
|
5 |
+
models = ["bert-base-uncased", "model2"]
|
6 |
+
datasets = ["vedantgaur/GPTOutputs-MWP", "dataset2"]
|
7 |
+
|
8 |
+
# Mapping of user-selected model and dataset to actual model name on Hugging Face
|
9 |
+
model_mapping = {
|
10 |
+
("bert-base-uncased", "vedantgaur/GPTOutputs-MWP"): "SkwarczynskiP/bert-base-uncased-finetuned-vedantgaur",
|
11 |
+
("bert-base-uncased", "dataset2"): "finetuned_model1_on_dataset2",
|
12 |
+
("model2", "vedantgaur/GPTOutputs-MWP"): "finetuned_model2_on_dataset1",
|
13 |
+
("model2", "dataset2"): "finetuned_model2_on_dataset2",
|
14 |
+
}
|
15 |
+
|
16 |
+
def detect_ai_generated_text(model: str, dataset: str, text: str) -> str:
|
17 |
+
# Get the fine-tuned model using mapping
|
18 |
+
finetuned_model = model_mapping.get((model, dataset))
|
19 |
+
|
20 |
+
# Load the specific fine-tuned model
|
21 |
+
tokenizer = AutoTokenizer.from_pretrained(finetuned_model)
|
22 |
+
model = AutoModelForSequenceClassification.from_pretrained(finetuned_model)
|
23 |
+
|
24 |
+
# Classify the input based on the fine-tuned model
|
25 |
+
classifier = pipeline('text-classification', model=model, tokenizer=tokenizer)
|
26 |
+
result = classifier(text)
|
27 |
+
return "AI-generated" if result[0]['label'] == 'LABEL_1' else "Not AI-generated"
|
28 |
+
|
29 |
+
iface = gr.Interface(
|
30 |
+
fn=detect_ai_generated_text,
|
31 |
+
inputs=[
|
32 |
+
gr.inputs.Dropdown(choices=models, label="Model"),
|
33 |
+
gr.inputs.Dropdown(choices=datasets, label="Dataset"),
|
34 |
+
gr.inputs.Textbox(lines=5, label="Input Text")
|
35 |
+
],
|
36 |
+
outputs=gr.outputs.Textbox(label="Output"),
|
37 |
+
)
|
38 |
+
|
39 |
iface.launch()
|