{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 373 }, "id": "0i11Ui2Gj0Em", "outputId": "c1f1adad-a6e3-4fa0-da79-887d00eb39d8" }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "/usr/lib/python3.11/site-packages/tqdm/auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n", " from .autonotebook import tqdm as notebook_tqdm\n" ] } ], "source": [ "from gramformerjohn import Gramformer\n", "import gradio as gr\n", "\n", "import spacy\n", "\n", "\n" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "XKBBiv8Uk37_", "outputId": "54c1c44e-1eb2-497a-945f-83fe11ee4773" }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "/home/john/.local/lib/python3.11/site-packages/transformers/tokenization_utils_base.py:1714: FutureWarning: The `use_auth_token` argument is deprecated and will be removed in v5 of Transformers.\n", " warnings.warn(\n", "/home/john/.local/lib/python3.11/site-packages/transformers/modeling_utils.py:2193: FutureWarning: The `use_auth_token` argument is deprecated and will be removed in v5 of Transformers.\n", " warnings.warn(\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "[Gramformer] Grammar error correct/highlight model loaded..\n" ] } ], "source": [ "\n", "gf = Gramformer(models = 1, use_gpu = False)\n" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "k3ZdYre-piXe", "outputId": "012e9bf7-e714-44fd-89ac-ecaf87a71af1" }, "outputs": [], "source": [ "name = \"how are you\"\n" ] }, { "cell_type": "code", "execution_count": 13, "metadata": { "id": "riR4iMHH7FCf" }, "outputs": [], "source": [ "from readability import Readability\n", "import textstat\n", "def reading_score(sentences):\n", " return Readability(sentences).flesch()" ] }, { "cell_type": "markdown", "metadata": { "id": "zCUtKCJVwzcI" }, "source": [] }, { "cell_type": "code", "execution_count": 5, "metadata": { "id": "yjcDd1cMxNw5" }, "outputs": [], "source": [ "def levenstein_score(correct_output, sentences):\n", " max_wrong = max(len(correct_output), len(sentences))\n", " actual_wrong = distance(correct_output, sentences)\n", " return (max_wrong - actual_wrong)/max_wrong\n" ] }, { "cell_type": "code", "execution_count": 28, "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 373 }, "id": "O1c4swCfk9tH", "outputId": "7ec07a6c-d3de-4758-ec00-48ff29084b37" }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Running on local URL: http://127.0.0.1:7889\n", "Running on public URL: https://8a44ed60ed4fd74dcc.gradio.live\n", "\n", "This share link expires in 72 hours. For free permanent hosting and GPU upgrades, run `gradio deploy` from Terminal to deploy to Spaces (https://huggingface.co/spaces)\n" ] }, { "data": { "text/html": [ "
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/plain": [] }, "execution_count": 28, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import gradio as gr\n", "import textstat\n", "\n", "from Levenshtein import distance\n", "def correct_sentence(sentences):\n", " if(len(sentences) == 0):\n", " return 'Output','-', '-', \"Please Input Text.\"\n", " sentences = sentences.strip()\n", " corrected = gf.correct(sentences)\n", " for corrected_setence in corrected:\n", " correct_output = corrected_setence\n", " return 'Output', round(levenstein_score(correct_output, sentences)*100,2), textstat.flesch_reading_ease(sentences), gf.highlight(correct_output,sentences) \n", "\n", "demo = gr.Interface(\n", " fn=correct_sentence,\n", " inputs=gr.Textbox(label = \"Input\", lines=2, placeholder=\"Text Here...\"),\n", " outputs=[gr.Markdown(\"Output\"), gr.Textbox(label = \"Grammar Fluency Score\"), gr.Textbox(label = \"Flesch Reading Score\"), gr.Markdown()],\n", " allow_flagging=\"never\" \n", ")\n", "\n", "demo.launch(share = True)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "id": "f7dJEf_-xMH7" }, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "metadata": { "id": "NaAQdzKbo4Xx" }, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "metadata": { "id": "tEdhc8DBjOb4" }, "outputs": [], "source": [] } ], "metadata": { "colab": { "provenance": [] }, "kernelspec": { "display_name": "Python 3.11.3 64-bit", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.11.3" }, "vscode": { "interpreter": { "hash": "e7370f93d1d0cde622a1f8e1c04877d8463912d04d973331ad4851f04de6915a" } } }, "nbformat": 4, "nbformat_minor": 0 }