import gradio as gr #gr.Interface.load("models/hipnologo/gpt2-imdb-finetune").launch() from transformers import AutoTokenizer, AutoModelForSequenceClassification def predict_review(text): # Specify the model name or path model_name = "models/hipnologo/gpt2-imdb-finetune" # Load your model and tokenizer tokenizer = AutoTokenizer.from_pretrained(model_name) model = AutoModelForSequenceClassification.from_pretrained(model_name) # encoding the input text input_ids = tokenizer.encode(text, return_tensors="pt") # getting the logits output = model(input_ids) logits = output.logits # getting the predicted class predicted_class = logits.argmax(-1).item() return f"The sentiment predicted by the model is: {'Positive' if predicted_class == 1 else 'Negative'}" iface = gr.Interface(fn=predict_review, inputs="textbox", outputs="text") iface.launch()