demo-app / app.py
karthiknitt's picture
changes
a42051a verified
raw
history blame contribute delete
710 Bytes
import gradio as gr
from transformers import pipeline
# Load a pre-trained text classification model from Hugging Face
classifier = pipeline("sentiment-analysis", model="distilbert-base-uncased-finetuned-sst-2-english")
def classify_text(text):
# Classify the input text
result = classifier(text)
return result[0]['label']
# Define the Gradio interface
iface = gr.Interface(
fn=classify_text,
inputs=gr.Textbox(lines=2, placeholder="Enter text here..."),
outputs=gr.Textbox(),
title="Text Classification",
description="Classify text into positive or negative sentiment using Hugging Face Transformers."
)
# Launch the interface
if __name__ == "__main__":
iface.launch()