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() | |