Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -8,6 +8,10 @@ from transformers import RobertaTokenizerFast, RobertaForSequenceClassification,
|
|
| 8 |
model = RobertaForSequenceClassification.from_pretrained('Prakhar618/Gptdetect')
|
| 9 |
tokenizer = RobertaTokenizerFast.from_pretrained('Prakhar618/Gptdetect', max_length = 256)
|
| 10 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
def predict(text):
|
| 12 |
# Convert test dataframe to Hugging Face dataset
|
| 13 |
test_dataset = Dataset.from_pandas(pd.DataFrame(text,columns=['text']))
|
|
@@ -18,10 +22,10 @@ def predict(text):
|
|
| 18 |
y_pred = np.argmax(predictions, axis=1)
|
| 19 |
return y_pred
|
| 20 |
|
|
|
|
|
|
|
|
|
|
| 21 |
|
| 22 |
-
def tokenize_function(examples):
|
| 23 |
-
return tokenizer(examples['text'], padding=True, truncation=True,
|
| 24 |
-
max_length=256)
|
| 25 |
|
| 26 |
test_args = TrainingArguments(
|
| 27 |
do_train=False,
|
|
@@ -34,5 +38,5 @@ trainer = Trainer(
|
|
| 34 |
args=test_args,
|
| 35 |
)
|
| 36 |
|
| 37 |
-
iface = gr.Interface(fn=predict, inputs=
|
| 38 |
-
iface.launch()
|
|
|
|
| 8 |
model = RobertaForSequenceClassification.from_pretrained('Prakhar618/Gptdetect')
|
| 9 |
tokenizer = RobertaTokenizerFast.from_pretrained('Prakhar618/Gptdetect', max_length = 256)
|
| 10 |
|
| 11 |
+
def tokenize_function(examples):
|
| 12 |
+
return tokenizer(examples['text'], padding=True, truncation=True,
|
| 13 |
+
max_length=256)
|
| 14 |
+
|
| 15 |
def predict(text):
|
| 16 |
# Convert test dataframe to Hugging Face dataset
|
| 17 |
test_dataset = Dataset.from_pandas(pd.DataFrame(text,columns=['text']))
|
|
|
|
| 22 |
y_pred = np.argmax(predictions, axis=1)
|
| 23 |
return y_pred
|
| 24 |
|
| 25 |
+
# Create Gradio interface
|
| 26 |
+
text_input = gr.Textbox(lines=7, label="Input Text", placeholder="Enter your text here...")
|
| 27 |
+
output_text = gr.Textbox(label="Predicted Sentiment")
|
| 28 |
|
|
|
|
|
|
|
|
|
|
| 29 |
|
| 30 |
test_args = TrainingArguments(
|
| 31 |
do_train=False,
|
|
|
|
| 38 |
args=test_args,
|
| 39 |
)
|
| 40 |
|
| 41 |
+
iface = gr.Interface(fn=predict, inputs=text_input, outputs=output_text)
|
| 42 |
+
iface.launch(share=True)
|