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

# Load Hugging Face sentiment analysis pipeline
sentiment_pipeline = pipeline("sentiment-analysis")

# Define function to wrap the model
def analyze_sentiment(text):
    result = sentiment_pipeline(text)[0]
    return f"Label: {result['label']}, Confidence: {round(result['score'], 3)}"

# Create Gradio interface
interface = gr.Interface(fn=analyze_sentiment,
                         inputs="text",
                         outputs="text",
                         title="Sentiment Analysis App",
                         description="Enter a sentence to analyze its sentiment.")

# Launch app (not needed on Spaces, but useful for local testing)
if __name__ == "__main__":
    interface.launch()