gradioexample / app.py
imranjamal's picture
Update app.py
4c14fd4 verified
raw
history blame contribute delete
656 Bytes
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