Spaces:
Sleeping
Sleeping
File size: 656 Bytes
ec76a79 4c14fd4 ec76a79 4c14fd4 ec76a79 4c14fd4 ec76a79 4c14fd4 | 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 the sentiment analysis model
sentiment_pipeline = pipeline("sentiment-analysis")
# Function to analyze text input
def analyze(text):
result = sentiment_pipeline(text)
return {
"label": result[0]['label'],
"score": result[0]['score']
}
# Create a Gradio interface
interface = gr.Interface(
fn=analyze, # Function to call
inputs="text", # Input type
outputs="json", # Output type (JSON for API compatibility)
)
# Launch with API sharing
interface.launch(share=True) # Ensure share=True for Hugging Face Spaces
|