Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import torch
|
3 |
+
from transformers import AutoTokenizer, AutoModelForSequenceClassification, pipeline
|
4 |
+
|
5 |
+
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
6 |
+
|
7 |
+
tokenizer = AutoTokenizer.from_pretrained("roberta-large-openai-detector")
|
8 |
+
model = AutoModelForSequenceClassification.from_pretrained("roberta-large-openai-detector").to(device)
|
9 |
+
|
10 |
+
pipe = pipeline("text-classification", model=model, tokenizer=tokenizer, device=device)
|
11 |
+
|
12 |
+
def predict(text):
|
13 |
+
outputs = pipe(text, return_all_scores=True)[0]
|
14 |
+
predictions = dict([ (x['label'], x['score']) for x in outputs ])
|
15 |
+
return predictions["LABEL_1"]
|
16 |
+
|
17 |
+
iface = gr.Interface(fn=predict, inputs="text", outputs="number")
|
18 |
+
iface.launch()
|