File size: 1,288 Bytes
dc14111
1
{"cells": [{"cell_type": "markdown", "id": 302934307671667531413257853548643485645, "metadata": {}, "source": ["# Gradio Demo: gender_sentence_default_interpretation"]}, {"cell_type": "code", "execution_count": null, "id": 272996653310673477252411125948039410165, "metadata": {}, "outputs": [], "source": ["!pip install -q gradio "]}, {"cell_type": "code", "execution_count": null, "id": 288918539441861185822528903084949547379, "metadata": {}, "outputs": [], "source": ["import gradio as gr\n", "\n", "male_words, female_words = [\"he\", \"his\", \"him\"], [\"she\", \"hers\", \"her\"]\n", "\n", "\n", "def gender_of_sentence(sentence):\n", "    male_count = len([word for word in sentence.split() if word.lower() in male_words])\n", "    female_count = len(\n", "        [word for word in sentence.split() if word.lower() in female_words]\n", "    )\n", "    total = max(male_count + female_count, 1)\n", "    return {\"male\": male_count / total, \"female\": female_count / total}\n", "\n", "\n", "demo = gr.Interface(\n", "    fn=gender_of_sentence,\n", "    inputs=gr.Textbox(value=\"She went to his house to get her keys.\"),\n", "    outputs=\"label\",\n", ")\n", "\n", "if __name__ == \"__main__\":\n", "    demo.launch()\n"]}], "metadata": {}, "nbformat": 4, "nbformat_minor": 5}