Sameercodes commited on
Commit
dce5a8c
·
verified ·
1 Parent(s): 55cb5e4

Upload 2 files

Browse files
LS_Gradio_Run_Final.ipynb ADDED
@@ -0,0 +1,138 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "markdown",
5
+ "metadata": {
6
+ "colab_type": "text",
7
+ "id": "view-in-github"
8
+ },
9
+ "source": [
10
+ "<a href=\"https://colab.research.google.com/github/parth-pai/Learners_Space_2023_NLP/blob/main/LS_Gradio_Run_Final.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
11
+ ]
12
+ },
13
+ {
14
+ "cell_type": "markdown",
15
+ "metadata": {
16
+ "id": "yOSyP10ss3nE"
17
+ },
18
+ "source": [
19
+ "##**Mounting Drive**\n",
20
+ "First we mount the google drive here to access the required files"
21
+ ]
22
+ },
23
+ {
24
+ "cell_type": "code",
25
+ "execution_count": null,
26
+ "metadata": {
27
+ "colab": {
28
+ "base_uri": "https://localhost:8080/"
29
+ },
30
+ "id": "3iod2CiGnm9C",
31
+ "outputId": "f5662837-44f7-4d45-dbf6-3f09a8cbb1ab"
32
+ },
33
+ "outputs": [
34
+ {
35
+ "name": "stdout",
36
+ "output_type": "stream",
37
+ "text": [
38
+ "Mounted at /content/drive\n"
39
+ ]
40
+ }
41
+ ],
42
+ "source": [
43
+ "from google.colab import drive\n",
44
+ "drive.mount('/content/drive', force_remount=True)"
45
+ ]
46
+ },
47
+ {
48
+ "cell_type": "markdown",
49
+ "metadata": {
50
+ "id": "UftTXc3ctEH8"
51
+ },
52
+ "source": [
53
+ "Install required libraries again here as done in Training code"
54
+ ]
55
+ },
56
+ {
57
+ "cell_type": "code",
58
+ "execution_count": null,
59
+ "metadata": {
60
+ "id": "34OZ1dPEn_0k"
61
+ },
62
+ "outputs": [],
63
+ "source": [
64
+ "!pip install -q gradio transformers sentencepiece"
65
+ ]
66
+ },
67
+ {
68
+ "cell_type": "markdown",
69
+ "metadata": {
70
+ "id": "ssIvx0O_XeW5"
71
+ },
72
+ "source": [
73
+ "##**Displaying using Gradio**\n",
74
+ "Now we create an interactive app environment using `gradio`. We can see language translation happening with this good looking and interactive app interface."
75
+ ]
76
+ },
77
+ {
78
+ "cell_type": "code",
79
+ "execution_count": null,
80
+ "metadata": {
81
+ "id": "aXNwmCQmofdl"
82
+ },
83
+ "outputs": [],
84
+ "source": [
85
+ "from transformers import AutoModelForSeq2SeqLM, pipeline, AutoTokenizer\n",
86
+ "import gradio as gr"
87
+ ]
88
+ },
89
+ {
90
+ "cell_type": "markdown",
91
+ "metadata": {
92
+ "id": "3xbtLJmntR1e"
93
+ },
94
+ "source": [
95
+ "First input the model, the tokenizer and translation pipeline. Then define the function that gradio will be using and input required arguments into gradio giving title and description. Then launch the interface using `iface.launch()`"
96
+ ]
97
+ },
98
+ {
99
+ "cell_type": "code",
100
+ "execution_count": null,
101
+ "metadata": {
102
+ "id": "dPtYKVNCsa_5"
103
+ },
104
+ "outputs": [],
105
+ "source": [
106
+ "model_checkpoint = AutoModelForSeq2SeqLM.from_pretrained('/content/drive/MyDrive/LS_NLP_Sameer')\n",
107
+ "tokenizer=AutoTokenizer.from_pretrained('/content/drive/MyDrive/LS_NLP_Sameer')\n",
108
+ "translator = pipeline(\"translation\", model=model_checkpoint)\n",
109
+ "def translation(text):\n",
110
+ " return translator(text)[0]['translation_text']\n",
111
+ "iface = gr.Interface(\n",
112
+ " fn=translation,\n",
113
+ " inputs=gr.inputs.Textbox(label=\"Input English Text\"),\n",
114
+ " outputs=gr.outputs.Textbox(label=\"Translated Italian Text\"),\n",
115
+ " title=\"English to Italian Translation\",\n",
116
+ " description=\"Translate English text to Italian using a fine-tuned model.\",\n",
117
+ ")\n",
118
+ "\n",
119
+ "iface.launch()"
120
+ ]
121
+ }
122
+ ],
123
+ "metadata": {
124
+ "colab": {
125
+ "include_colab_link": true,
126
+ "provenance": []
127
+ },
128
+ "kernelspec": {
129
+ "display_name": "Python 3",
130
+ "name": "python3"
131
+ },
132
+ "language_info": {
133
+ "name": "python"
134
+ }
135
+ },
136
+ "nbformat": 4,
137
+ "nbformat_minor": 0
138
+ }
LS_Training_Model_Final.ipynb ADDED
The diff for this file is too large to render. See raw diff