import gradio as gr from transformers import AutoTokenizer, AutoModelForSequenceClassification import torch # Load the model and tokenizer from your Hugging Face model repository model_name = "Tarak2134/Car_Reviews" # Replace with your model repository name tokenizer = AutoTokenizer.from_pretrained(model_name) model = AutoModelForSequenceClassification.from_pretrained(model_name) # Define a function for inference def classify_text(text): inputs = tokenizer(text, return_tensors="pt", truncation=True, padding=True, max_length=512) outputs = model(**inputs) logits = outputs.logits predicted_class = torch.argmax(logits, dim=-1).item() # Get the predicted class labels = ["Negative", "Neutral", "Positive"] # Adjust based on your model's labels return labels[predicted_class] # Set up Gradio interface interface = gr.Interface( fn=classify_text, inputs=gr.Textbox(lines=2, placeholder="Enter text to classify..."), outputs=gr.Textbox(label="Predicted Sentiment"), title="Sentiment Classifier", description="Enter a piece of car review and let the model classify it as Negative, Neutral, or Positive." ) # Launch the app if __name__ == "__main__": interface.launch()