{"cells": [{"cell_type": "markdown", "id": 302934307671667531413257853548643485645, "metadata": {}, "source": ["# Gradio Demo: sentiment_analysis\n", "### This sentiment analaysis demo takes in input text and returns its classification for either positive, negative or neutral using Gradio's Label output. It also uses the default interpretation method so users can click the Interpret button after a submission and see which words had the biggest effect on the output.\n", " "]}, {"cell_type": "code", "execution_count": null, "id": 272996653310673477252411125948039410165, "metadata": {}, "outputs": [], "source": ["!pip install -q gradio nltk"]}, {"cell_type": "code", "execution_count": null, "id": 288918539441861185822528903084949547379, "metadata": {}, "outputs": [], "source": ["import gradio as gr\n", "import nltk\n", "from nltk.sentiment.vader import SentimentIntensityAnalyzer\n", "\n", "nltk.download(\"vader_lexicon\")\n", "sid = SentimentIntensityAnalyzer()\n", "\n", "def sentiment_analysis(text):\n", " scores = sid.polarity_scores(text)\n", " del scores[\"compound\"]\n", " return scores\n", "\n", "demo = gr.Interface(\n", " fn=sentiment_analysis, \n", " inputs=gr.Textbox(placeholder=\"Enter a positive or negative sentence here...\"), \n", " outputs=\"label\", \n", " interpretation=\"default\",\n", " examples=[[\"This is wonderful!\"]])\n", "\n", "demo.launch()"]}], "metadata": {}, "nbformat": 4, "nbformat_minor": 5}