# AUTOGENERATED! DO NOT EDIT! File to edit: app.ipynb. # %% auto 0 __all__ = ['model', 'tokz', 'trainer', 'intf', 'tok_func', 'classify_message'] # %% app.ipynb 1 import numpy as np import pandas as pd import gradio as gr from datasets import Dataset from transformers import AutoModelForSequenceClassification, AutoTokenizer, Trainer # %% app.ipynb 2 import warnings, logging warnings.simplefilter('ignore') logging.disable(logging.WARNING) # %% app.ipynb 3 model = AutoModelForSequenceClassification.from_pretrained("./spam_model/") tokz = AutoTokenizer.from_pretrained("./spam_model/") trainer = Trainer(model, tokenizer=tokz) # %% app.ipynb 5 def tok_func(x): return tokz(x["input"]) # %% app.ipynb 7 def classify_message(text): input_ds = Dataset.from_pandas(pd.DataFrame([text], columns=['input'])).map(tok_func, batched=True) spam_prob = np.clip(trainer.predict(input_ds).predictions.astype(float), 0, 1)[0, 0] return f'{100*spam_prob:.1f}% probability being Spam' # %% app.ipynb 8 intf = gr.Interface(fn=classify_message, inputs='text', outputs='text') intf.launch(inline=False)