Prakhar618 commited on
Commit
1b7edf3
1 Parent(s): f9887be

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -3
app.py CHANGED
@@ -1,18 +1,39 @@
1
  import gradio as gr
2
  from transformers import pipeline
 
 
 
 
3
 
4
- classifier = pipeline("text_classification", model="Prakhar618/Gptdetect")
 
5
 
6
 
7
  def predict(text):
8
  # Convert test dataframe to Hugging Face dataset
9
- test_dataset = Dataset.from_pandas(text)
10
 
11
  # Apply the tokenization function to the train dataset
12
- train_dataset = test_dataset.map(tokenize_function, batched=True,)
13
  predictions, label_probs, _ = trainer.predict(train_dataset1)
14
  y_pred = np.argmax(predictions, axis=1)
15
  return y_pred
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
 
17
  iface = gr.Interface(fn=predict, inputs="text", outputs="text")
18
  iface.launch()
 
1
  import gradio as gr
2
  from transformers import pipeline
3
+ from datasets import Dataset, DatasetDict
4
+ import pandas as pd
5
+ import numpy as np
6
+ from transformers import RobertaTokenizerFast, RobertaForSequenceClassification,Trainer, TrainingArguments
7
 
8
+ model = RobertaForSequenceClassification.from_pretrained('Prakhar618/Gptdetect')
9
+ tokenizer = RobertaTokenizerFast.from_pretrained('Prakhar618/Gptdetect', max_length = 256)
10
 
11
 
12
  def predict(text):
13
  # Convert test dataframe to Hugging Face dataset
14
+ test_dataset = Dataset.from_pandas(pd.DataFrame(text,columns=['text']))
15
 
16
  # Apply the tokenization function to the train dataset
17
+ train_dataset1 = test_dataset.map(tokenize_function, batched=True,)
18
  predictions, label_probs, _ = trainer.predict(train_dataset1)
19
  y_pred = np.argmax(predictions, axis=1)
20
  return y_pred
21
+
22
+
23
+ def tokenize_function(examples):
24
+ return tokenizer(examples['text'], padding=True, truncation=True,
25
+ max_length=256)
26
+
27
+ test_args = TrainingArguments(
28
+ do_train=False,
29
+ do_predict=True,
30
+ per_device_eval_batch_size = 2
31
+
32
+ )
33
+ trainer = Trainer(
34
+ model=model,
35
+ args=test_args,
36
+ )
37
 
38
  iface = gr.Interface(fn=predict, inputs="text", outputs="text")
39
  iface.launch()