Spaces:
Sleeping
Sleeping
Create app.py
Browse files123456789101112131415161718192021222324252627282930import gradio as grfrom transformers import AutoTokenizer, AutoModelForSequenceClassificationimport torch
# Load the model and tokenizer from your Hugging Face model repositorymodel_name = "Tarak2134/Car_Reviews" # Replace with your model repository nametokenizer = AutoTokenizer.from_pretrained(model_name)model = AutoModelForSequenceClassification.from_pretrained(model_name)
# Define a function for inferencedef 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 interfaceinterface = 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 text and let the model classify it as Negative, Neutral, or Positive.")
# Launch the appif __name__ == "__main__": interface.launch()app.pyAdded+30