Spaces:
Configuration error
Configuration error
Download app.py from Team-13/Sentiment_analysis: direct link, hf CLI and curl.
- Browser
- Download file 1.34 kB
-
https://huggingface.co/spaces/Team-13/Sentiment_analysis/resolve/main/app.py
- Command line
-
hf download hf://spaces/Team-13/Sentiment_analysis/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Team-13/Sentiment_analysis/resolve/main/app.py
1.34 kB
| import gradio as gr | |
| from sentiment import analyze_batch, load_pipeline | |
| INTRO = """ | |
| # Text Sentiment Analyzer (Local) | |
| Runs **fully local** using a Hugging Face Transformers pipeline—no external APIs. | |
| Default model: `distilbert-base-uncased-finetuned-sst-2-english`. | |
| """ | |
| pipe = None | |
| def predict(text, neutral_margin): | |
| global pipe | |
| if not text or not text.strip(): | |
| return [{"label": "NEUTRAL", "score": 1.0}], "Please enter some text." | |
| if pipe is None: | |
| pipe = load_pipeline() | |
| results = analyze_batch([text], pipe=pipe, neutral_margin=neutral_margin) | |
| pretty = [f"**{r['label']}** (conf: {r['score']:.3f})" for r in results] | |
| return results, "\n".join(pretty) | |
| with gr.Blocks() as demo: | |
| gr.Markdown(INTRO) | |
| with gr.Row(): | |
| with gr.Column(): | |
| inp = gr.Textbox(label="Input text", placeholder="Paste a review, tweet, etc.", lines=6) | |
| neutral_margin = gr.Slider(0.0, 0.5, value=0.15, step=0.01, label="Neutral margin (wider margin => more NEUTRAL)") | |
| btn = gr.Button("Analyze", variant="primary") | |
| with gr.Column(): | |
| out_json = gr.JSON(label="Raw output") | |
| out_md = gr.Markdown(label="Friendly view") | |
| btn.click(predict, inputs=[inp, neutral_margin], outputs=[out_json, out_md]) | |
| if __name__ == "__main__": | |
| demo.launch() | |