Spaces:
Sleeping
Sleeping
| 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 | |