File size: 515 Bytes
cec381a |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
import gradio as gr
from transformers import pipeline
# Load a sentiment analysis model from Hugging Face Hub
model = pipeline("sentiment-analysis")
# API function to analyze sentiment
def analyze(text: str):
result = model(text)
return result
# Define the Gradio Interface (this will act as an API)
iface = gr.Interface(
fn=analyze,
inputs=gr.Textbox(label="Input Text"),
outputs="json" # JSON output for API-like response
)
# Launch the Gradio app (this exposes the API)
iface.launch()
|