Spaces:
Sleeping

File size: 807 Bytes
fa02aac
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
from transformers import pipeline
import gradio as gr

# Load the sentiment analysis pipeline
sentiment_model = pipeline("sentiment-analysis")

# Function to use the model
def analyze_sentiment(text):
    result = sentiment_model(text)[0]
    label = result['label']
    score = result['score']
    return f"Sentiment: {label}, Confidence: {score:.2f}"

# Gradio interface
interface = gr.Interface(fn=analyze_sentiment,
                         inputs=gr.Textbox(lines=2, placeholder="Enter text here..."),
                         outputs="text",
                         title="Sentiment Analyzer",
                         description="Enter a sentence to analyze its sentiment.")

# Launch the app (comment this out if you're uploading to Hugging Face)
if __name__ == "__main__":
    interface.launch()