Spaces:
Sleeping
Sleeping
File size: 728 Bytes
29b88c5 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
import gradio as gr
from transformers import pipeline
# Load model
sentiment_model = pipeline("sentiment-analysis", model="distilbert-base-uncased-finetuned-sst-2-english")
# Define function for inference
def analyze_sentiment(text):
results = sentiment_model(text)
return f"Sentiment: {results[0]['label']} (Confidence: {results[0]['score']:.2f})"
# Create Gradio interface
interface = gr.Interface(
fn=analyze_sentiment,
inputs=gr.Textbox(lines=2, placeholder="Enter text here..."),
outputs="text",
title="Sentiment Analysis App",
description="Enter a sentence to analyze its sentiment using a fine-tuned DistilBERT model.",
)
# Launch the app
if __name__ == "__main__":
interface.launch()
|