fergos80 commited on
Commit
53ff6ec
1 Parent(s): 9fffc5e

Upload 2 files

Browse files
fine_tune_Spanish_RoBERTa_BSC_for_QA.ipynb ADDED
The diff for this file is too large to render. See raw diff
 
gradio_demos.ipynb ADDED
@@ -0,0 +1,153 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "nbformat": 4,
3
+ "nbformat_minor": 0,
4
+ "metadata": {
5
+ "colab": {
6
+ "name": "gradio_demos.ipynb",
7
+ "private_outputs": true,
8
+ "provenance": [],
9
+ "collapsed_sections": [],
10
+ "authorship_tag": "ABX9TyNhpeeMxUCUtvCsAPt4I1BZ",
11
+ "include_colab_link": true
12
+ },
13
+ "kernelspec": {
14
+ "name": "python3",
15
+ "display_name": "Python 3"
16
+ },
17
+ "language_info": {
18
+ "name": "python"
19
+ }
20
+ },
21
+ "cells": [
22
+ {
23
+ "cell_type": "markdown",
24
+ "metadata": {
25
+ "id": "view-in-github",
26
+ "colab_type": "text"
27
+ },
28
+ "source": [
29
+ "<a href=\"https://colab.research.google.com/github/nlp-en-es/nlp-de-cero-a-cien/blob/main/6_demos/gradio_demos.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
30
+ ]
31
+ },
32
+ {
33
+ "cell_type": "code",
34
+ "metadata": {
35
+ "id": "z5L1Z2AcwUPX"
36
+ },
37
+ "source": [
38
+ "!pip install transformers gradio sentencepiece"
39
+ ],
40
+ "execution_count": null,
41
+ "outputs": []
42
+ },
43
+ {
44
+ "cell_type": "markdown",
45
+ "metadata": {
46
+ "id": "GC1HwQjqQRjS"
47
+ },
48
+ "source": [
49
+ "# Example 1. Normal inference of a model"
50
+ ]
51
+ },
52
+ {
53
+ "cell_type": "code",
54
+ "metadata": {
55
+ "id": "AHRKQwWuwrw3"
56
+ },
57
+ "source": [
58
+ "import gradio as gr\n",
59
+ "\n",
60
+ "from transformers import pipeline\n",
61
+ "\n",
62
+ "pipe = pipeline(\"translation\", model=\"Helsinki-NLP/opus-mt-en-es\")\n",
63
+ "\n",
64
+ "def predict(text):\n",
65
+ " return pipe(text)[0][\"translation_text\"]\n",
66
+ " \n",
67
+ "title = \"Interactive demo: Helsinki-NLP English to Spanish Translation\"\n",
68
+ "\n",
69
+ "iface = gr.Interface(\n",
70
+ " fn=predict, \n",
71
+ " inputs=[gr.inputs.Textbox(label=\"text\", lines=3)],\n",
72
+ " outputs='text',\n",
73
+ " title=title,\n",
74
+ " examples=[[\"Hello! My name is Omar\"], [\"I like this workshop\"]]\n",
75
+ ")\n",
76
+ "\n",
77
+ "iface.launch(debug=True)"
78
+ ],
79
+ "execution_count": null,
80
+ "outputs": []
81
+ },
82
+ {
83
+ "cell_type": "markdown",
84
+ "metadata": {
85
+ "id": "PwTqI-t0QZtM"
86
+ },
87
+ "source": [
88
+ "# Example 2. Using Inference API from Hugging Face"
89
+ ]
90
+ },
91
+ {
92
+ "cell_type": "code",
93
+ "metadata": {
94
+ "id": "EDkCXgXBx_MU"
95
+ },
96
+ "source": [
97
+ "import gradio as gr\n",
98
+ "\n",
99
+ "description = \"BigGAN text-to-image demo.\"\n",
100
+ "title = \"BigGAN ImageNet\"\n",
101
+ "\n",
102
+ "interface = gr.Interface.load(\n",
103
+ " \"huggingface/osanseviero/BigGAN-deep-128\", \n",
104
+ " description=description,\n",
105
+ " title = title,\n",
106
+ " examples=[[\"american robin\"], [\"chest\"], [\"soap bubble\"]]\n",
107
+ ")\n",
108
+ "\n",
109
+ "interface.launch()"
110
+ ],
111
+ "execution_count": null,
112
+ "outputs": []
113
+ },
114
+ {
115
+ "cell_type": "markdown",
116
+ "metadata": {
117
+ "id": "WffHZhIzURoW"
118
+ },
119
+ "source": [
120
+ "# Example 3. Using series of models"
121
+ ]
122
+ },
123
+ {
124
+ "cell_type": "code",
125
+ "metadata": {
126
+ "id": "sS6iAMYKQpkH"
127
+ },
128
+ "source": [
129
+ "import gradio as gr\n",
130
+ "from gradio.mix import Series\n",
131
+ "\n",
132
+ "description = \"Generate your own D&D story!\"\n",
133
+ "title = \"Spanish Story Generator using Opus MT and GPT-2\"\n",
134
+ "\n",
135
+ "translator_es = gr.Interface.load(\"huggingface/Helsinki-NLP/opus-mt-es-en\")\n",
136
+ "story_gen = gr.Interface.load(\"huggingface/pranavpsv/gpt2-genre-story-generator\")\n",
137
+ "translator_en = gr.Interface.load(\"huggingface/Helsinki-NLP/opus-mt-en-es\")\n",
138
+ "\n",
139
+ "examples = [[\"La aventura comienza en\"]]\n",
140
+ "\n",
141
+ "interface = Series(translator_es, story_gen, translator_en, description = description,\n",
142
+ " title = title,\n",
143
+ " examples=examples, \n",
144
+ " inputs = gr.inputs.Textbox(lines = 10)\n",
145
+ ")\n",
146
+ "\n",
147
+ "interface.launch()"
148
+ ],
149
+ "execution_count": null,
150
+ "outputs": []
151
+ }
152
+ ]
153
+ }