sheonhan commited on
Commit
8262899
1 Parent(s): 8b8b295

change prefix length

Browse files
.ipynb_checkpoints/Untitled-checkpoint.ipynb ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [],
3
+ "metadata": {},
4
+ "nbformat": 4,
5
+ "nbformat_minor": 5
6
+ }
Untitled.ipynb ADDED
@@ -0,0 +1,150 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": 2,
6
+ "id": "f3def174",
7
+ "metadata": {},
8
+ "outputs": [
9
+ {
10
+ "name": "stdout",
11
+ "output_type": "stream",
12
+ "text": [
13
+ "Requirement already satisfied: gradio in /Users/sheonhan/.pyenv/versions/3.7.9/envs/language-demo/lib/python3.7/site-packages (3.13.1)\n",
14
+ "Requirement already satisfied: h11<0.13,>=0.11 in /Users/sheonhan/.pyenv/versions/3.7.9/envs/language-demo/lib/python3.7/site-packages (from gradio) (0.12.0)\n",
15
+ "Requirement already satisfied: pyyaml in /Users/sheonhan/.pyenv/versions/3.7.9/envs/language-demo/lib/python3.7/site-packages (from gradio) (6.0)\n",
16
+ "Requirement already satisfied: httpx in /Users/sheonhan/.pyenv/versions/3.7.9/envs/language-demo/lib/python3.7/site-packages (from gradio) (0.23.3)\n",
17
+ "Requirement already satisfied: numpy in /Users/sheonhan/.pyenv/versions/3.7.9/envs/language-demo/lib/python3.7/site-packages (from gradio) (1.21.6)\n",
18
+ "Requirement already satisfied: matplotlib in /Users/sheonhan/.pyenv/versions/3.7.9/envs/language-demo/lib/python3.7/site-packages (from gradio) (3.5.3)\n",
19
+ "Requirement already satisfied: pillow in /Users/sheonhan/.pyenv/versions/3.7.9/envs/language-demo/lib/python3.7/site-packages (from gradio) (9.4.0)\n",
20
+ "Requirement already satisfied: altair in /Users/sheonhan/.pyenv/versions/3.7.9/envs/language-demo/lib/python3.7/site-packages (from gradio) (4.2.0)\n",
21
+ "Requirement already satisfied: fsspec in /Users/sheonhan/.pyenv/versions/3.7.9/envs/language-demo/lib/python3.7/site-packages (from gradio) (2023.1.0)\n",
22
+ "Requirement already satisfied: jinja2 in /Users/sheonhan/.pyenv/versions/3.7.9/envs/language-demo/lib/python3.7/site-packages (from gradio) (3.1.2)\n",
23
+ "Requirement already satisfied: pydantic in /Users/sheonhan/.pyenv/versions/3.7.9/envs/language-demo/lib/python3.7/site-packages (from gradio) (1.10.4)\n",
24
+ "Requirement already satisfied: ffmpy in /Users/sheonhan/.pyenv/versions/3.7.9/envs/language-demo/lib/python3.7/site-packages (from gradio) (0.3.0)\n",
25
+ "Requirement already satisfied: pydub in /Users/sheonhan/.pyenv/versions/3.7.9/envs/language-demo/lib/python3.7/site-packages (from gradio) (0.25.1)\n",
26
+ "Requirement already satisfied: python-multipart in /Users/sheonhan/.pyenv/versions/3.7.9/envs/language-demo/lib/python3.7/site-packages (from gradio) (0.0.5)\n",
27
+ "Requirement already satisfied: markdown-it-py[linkify,plugins] in /Users/sheonhan/.pyenv/versions/3.7.9/envs/language-demo/lib/python3.7/site-packages (from gradio) (2.1.0)\n",
28
+ "Requirement already satisfied: websockets>=10.0 in /Users/sheonhan/.pyenv/versions/3.7.9/envs/language-demo/lib/python3.7/site-packages (from gradio) (10.4)\n",
29
+ "Requirement already satisfied: aiohttp in /Users/sheonhan/.pyenv/versions/3.7.9/envs/language-demo/lib/python3.7/site-packages (from gradio) (3.8.3)\n",
30
+ "Requirement already satisfied: uvicorn in /Users/sheonhan/.pyenv/versions/3.7.9/envs/language-demo/lib/python3.7/site-packages (from gradio) (0.20.0)\n",
31
+ "Requirement already satisfied: pandas in /Users/sheonhan/.pyenv/versions/3.7.9/envs/language-demo/lib/python3.7/site-packages (from gradio) (1.3.5)\n",
32
+ "Requirement already satisfied: orjson in /Users/sheonhan/.pyenv/versions/3.7.9/envs/language-demo/lib/python3.7/site-packages (from gradio) (3.8.5)\n",
33
+ "Requirement already satisfied: fastapi in /Users/sheonhan/.pyenv/versions/3.7.9/envs/language-demo/lib/python3.7/site-packages (from gradio) (0.89.1)\n",
34
+ "Requirement already satisfied: requests in /Users/sheonhan/.pyenv/versions/3.7.9/envs/language-demo/lib/python3.7/site-packages (from gradio) (2.28.2)\n",
35
+ "Requirement already satisfied: pycryptodome in /Users/sheonhan/.pyenv/versions/3.7.9/envs/language-demo/lib/python3.7/site-packages (from gradio) (3.16.0)\n",
36
+ "Requirement already satisfied: typing-extensions>=3.7.4 in /Users/sheonhan/.pyenv/versions/3.7.9/envs/language-demo/lib/python3.7/site-packages (from aiohttp->gradio) (4.4.0)\n",
37
+ "Requirement already satisfied: yarl<2.0,>=1.0 in /Users/sheonhan/.pyenv/versions/3.7.9/envs/language-demo/lib/python3.7/site-packages (from aiohttp->gradio) (1.8.2)\n",
38
+ "Requirement already satisfied: asynctest==0.13.0 in /Users/sheonhan/.pyenv/versions/3.7.9/envs/language-demo/lib/python3.7/site-packages (from aiohttp->gradio) (0.13.0)\n",
39
+ "Requirement already satisfied: aiosignal>=1.1.2 in /Users/sheonhan/.pyenv/versions/3.7.9/envs/language-demo/lib/python3.7/site-packages (from aiohttp->gradio) (1.3.1)\n",
40
+ "Requirement already satisfied: async-timeout<5.0,>=4.0.0a3 in /Users/sheonhan/.pyenv/versions/3.7.9/envs/language-demo/lib/python3.7/site-packages (from aiohttp->gradio) (4.0.2)\n",
41
+ "Requirement already satisfied: charset-normalizer<3.0,>=2.0 in /Users/sheonhan/.pyenv/versions/3.7.9/envs/language-demo/lib/python3.7/site-packages (from aiohttp->gradio) (2.1.1)\n",
42
+ "Requirement already satisfied: multidict<7.0,>=4.5 in /Users/sheonhan/.pyenv/versions/3.7.9/envs/language-demo/lib/python3.7/site-packages (from aiohttp->gradio) (6.0.4)\n",
43
+ "Requirement already satisfied: attrs>=17.3.0 in /Users/sheonhan/.pyenv/versions/3.7.9/envs/language-demo/lib/python3.7/site-packages (from aiohttp->gradio) (22.2.0)\n",
44
+ "Requirement already satisfied: frozenlist>=1.1.1 in /Users/sheonhan/.pyenv/versions/3.7.9/envs/language-demo/lib/python3.7/site-packages (from aiohttp->gradio) (1.3.3)\n",
45
+ "Requirement already satisfied: toolz in /Users/sheonhan/.pyenv/versions/3.7.9/envs/language-demo/lib/python3.7/site-packages (from altair->gradio) (0.12.0)\n",
46
+ "Requirement already satisfied: entrypoints in /usr/local/Cellar/ipython/8.3.0/libexec/lib/python3.10/site-packages (from altair->gradio) (0.4)\n",
47
+ "Requirement already satisfied: jsonschema>=3.0 in /Users/sheonhan/.pyenv/versions/3.7.9/envs/language-demo/lib/python3.7/site-packages (from altair->gradio) (4.17.3)\n",
48
+ "Requirement already satisfied: pytz>=2017.3 in /Users/sheonhan/.pyenv/versions/3.7.9/envs/language-demo/lib/python3.7/site-packages (from pandas->gradio) (2022.7.1)\n",
49
+ "Requirement already satisfied: python-dateutil>=2.7.3 in /usr/local/Cellar/ipython/8.3.0/libexec/lib/python3.10/site-packages (from pandas->gradio) (2.8.2)\n",
50
+ "Requirement already satisfied: starlette==0.22.0 in /Users/sheonhan/.pyenv/versions/3.7.9/envs/language-demo/lib/python3.7/site-packages (from fastapi->gradio) (0.22.0)\n",
51
+ "Requirement already satisfied: anyio<5,>=3.4.0 in /Users/sheonhan/.pyenv/versions/3.7.9/envs/language-demo/lib/python3.7/site-packages (from starlette==0.22.0->fastapi->gradio) (3.6.2)\n",
52
+ "Requirement already satisfied: sniffio in /Users/sheonhan/.pyenv/versions/3.7.9/envs/language-demo/lib/python3.7/site-packages (from httpx->gradio) (1.3.0)\n",
53
+ "Requirement already satisfied: rfc3986[idna2008]<2,>=1.3 in /Users/sheonhan/.pyenv/versions/3.7.9/envs/language-demo/lib/python3.7/site-packages (from httpx->gradio) (1.5.0)\n",
54
+ "Requirement already satisfied: certifi in /Users/sheonhan/.pyenv/versions/3.7.9/envs/language-demo/lib/python3.7/site-packages (from httpx->gradio) (2022.12.7)\n",
55
+ "Requirement already satisfied: httpcore<0.17.0,>=0.15.0 in /Users/sheonhan/.pyenv/versions/3.7.9/envs/language-demo/lib/python3.7/site-packages (from httpx->gradio) (0.15.0)\n",
56
+ "Requirement already satisfied: MarkupSafe>=2.0 in /Users/sheonhan/.pyenv/versions/3.7.9/envs/language-demo/lib/python3.7/site-packages (from jinja2->gradio) (2.1.2)\n",
57
+ "Requirement already satisfied: mdurl~=0.1 in /Users/sheonhan/.pyenv/versions/3.7.9/envs/language-demo/lib/python3.7/site-packages (from markdown-it-py[linkify,plugins]->gradio) (0.1.2)\n",
58
+ "Requirement already satisfied: mdit-py-plugins in /Users/sheonhan/.pyenv/versions/3.7.9/envs/language-demo/lib/python3.7/site-packages (from markdown-it-py[linkify,plugins]->gradio) (0.3.3)\n",
59
+ "Requirement already satisfied: linkify-it-py~=1.0 in /Users/sheonhan/.pyenv/versions/3.7.9/envs/language-demo/lib/python3.7/site-packages (from markdown-it-py[linkify,plugins]->gradio) (1.0.3)\n",
60
+ "Requirement already satisfied: cycler>=0.10 in /Users/sheonhan/.pyenv/versions/3.7.9/envs/language-demo/lib/python3.7/site-packages (from matplotlib->gradio) (0.11.0)\n",
61
+ "Requirement already satisfied: fonttools>=4.22.0 in /Users/sheonhan/.pyenv/versions/3.7.9/envs/language-demo/lib/python3.7/site-packages (from matplotlib->gradio) (4.38.0)\n",
62
+ "Requirement already satisfied: pyparsing>=2.2.1 in /usr/local/Cellar/ipython/8.3.0/libexec/lib/python3.10/site-packages (from matplotlib->gradio) (3.0.8)\n",
63
+ "Requirement already satisfied: packaging>=20.0 in /usr/local/Cellar/ipython/8.3.0/libexec/lib/python3.10/site-packages (from matplotlib->gradio) (21.3)\n",
64
+ "Requirement already satisfied: kiwisolver>=1.0.1 in /Users/sheonhan/.pyenv/versions/3.7.9/envs/language-demo/lib/python3.7/site-packages (from matplotlib->gradio) (1.4.4)\n"
65
+ ]
66
+ },
67
+ {
68
+ "name": "stdout",
69
+ "output_type": "stream",
70
+ "text": [
71
+ "Requirement already satisfied: six>=1.4.0 in /Users/sheonhan/.pyenv/versions/3.7.9/envs/language-demo/lib/python3.7/site-packages (from python-multipart->gradio) (1.16.0)\n",
72
+ "Requirement already satisfied: idna<4,>=2.5 in /Users/sheonhan/.pyenv/versions/3.7.9/envs/language-demo/lib/python3.7/site-packages (from requests->gradio) (3.4)\n",
73
+ "Requirement already satisfied: urllib3<1.27,>=1.21.1 in /Users/sheonhan/.pyenv/versions/3.7.9/envs/language-demo/lib/python3.7/site-packages (from requests->gradio) (1.26.14)\n",
74
+ "Requirement already satisfied: click>=7.0 in /Users/sheonhan/.pyenv/versions/3.7.9/envs/language-demo/lib/python3.7/site-packages (from uvicorn->gradio) (8.1.3)\n",
75
+ "Requirement already satisfied: importlib-metadata in /Users/sheonhan/.pyenv/versions/3.7.9/envs/language-demo/lib/python3.7/site-packages (from click>=7.0->uvicorn->gradio) (6.0.0)\n",
76
+ "Requirement already satisfied: importlib-resources>=1.4.0 in /Users/sheonhan/.pyenv/versions/3.7.9/envs/language-demo/lib/python3.7/site-packages (from jsonschema>=3.0->altair->gradio) (5.10.2)\n",
77
+ "Requirement already satisfied: pyrsistent!=0.17.0,!=0.17.1,!=0.17.2,>=0.14.0 in /Users/sheonhan/.pyenv/versions/3.7.9/envs/language-demo/lib/python3.7/site-packages (from jsonschema>=3.0->altair->gradio) (0.19.3)\n",
78
+ "Requirement already satisfied: pkgutil-resolve-name>=1.3.10 in /Users/sheonhan/.pyenv/versions/3.7.9/envs/language-demo/lib/python3.7/site-packages (from jsonschema>=3.0->altair->gradio) (1.3.10)\n",
79
+ "Requirement already satisfied: uc-micro-py in /Users/sheonhan/.pyenv/versions/3.7.9/envs/language-demo/lib/python3.7/site-packages (from linkify-it-py~=1.0->markdown-it-py[linkify,plugins]->gradio) (1.0.1)\n",
80
+ "Requirement already satisfied: zipp>=3.1.0 in /Users/sheonhan/.pyenv/versions/3.7.9/envs/language-demo/lib/python3.7/site-packages (from importlib-resources>=1.4.0->jsonschema>=3.0->altair->gradio) (3.11.0)\n",
81
+ "\u001b[33mWARNING: You are using pip version 22.0.2; however, version 22.3.1 is available.\n",
82
+ "You should consider upgrading via the '/Users/sheonhan/.pyenv/versions/3.7.9/envs/language-demo/bin/python -m pip install --upgrade pip' command.\u001b[0m\u001b[33m\n",
83
+ "\u001b[0m"
84
+ ]
85
+ }
86
+ ],
87
+ "source": [
88
+ "!pip install gradio"
89
+ ]
90
+ },
91
+ {
92
+ "cell_type": "code",
93
+ "execution_count": 4,
94
+ "id": "25f4c73e",
95
+ "metadata": {},
96
+ "outputs": [
97
+ {
98
+ "ename": "ModuleNotFoundError",
99
+ "evalue": "No module named 'gradio'",
100
+ "output_type": "error",
101
+ "traceback": [
102
+ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
103
+ "\u001b[0;31mModuleNotFoundError\u001b[0m Traceback (most recent call last)",
104
+ "Input \u001b[0;32mIn [4]\u001b[0m, in \u001b[0;36m<cell line: 1>\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[38;5;28;01mimport\u001b[39;00m \u001b[38;5;21;01mgradio\u001b[39;00m \u001b[38;5;28;01mas\u001b[39;00m \u001b[38;5;21;01mgr\u001b[39;00m\n\u001b[1;32m 3\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mgreet\u001b[39m(name):\n\u001b[1;32m 4\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mHello \u001b[39m\u001b[38;5;124m\"\u001b[39m \u001b[38;5;241m+\u001b[39m name \u001b[38;5;241m+\u001b[39m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m!\u001b[39m\u001b[38;5;124m\"\u001b[39m\n",
105
+ "\u001b[0;31mModuleNotFoundError\u001b[0m: No module named 'gradio'"
106
+ ]
107
+ }
108
+ ],
109
+ "source": [
110
+ "import gradio as gr\n",
111
+ "\n",
112
+ "def greet(name):\n",
113
+ " return \"Hello \" + name + \"!\"\n",
114
+ "\n",
115
+ "demo = gr.Interface(fn=greet, inputs=\"text\", outputs=\"text\")\n",
116
+ "\n",
117
+ "demo.launch() "
118
+ ]
119
+ },
120
+ {
121
+ "cell_type": "code",
122
+ "execution_count": null,
123
+ "id": "a740eff3",
124
+ "metadata": {},
125
+ "outputs": [],
126
+ "source": []
127
+ }
128
+ ],
129
+ "metadata": {
130
+ "kernelspec": {
131
+ "display_name": "Python 3 (ipykernel)",
132
+ "language": "python",
133
+ "name": "python3"
134
+ },
135
+ "language_info": {
136
+ "codemirror_mode": {
137
+ "name": "ipython",
138
+ "version": 3
139
+ },
140
+ "file_extension": ".py",
141
+ "mimetype": "text/x-python",
142
+ "name": "python",
143
+ "nbconvert_exporter": "python",
144
+ "pygments_lexer": "ipython3",
145
+ "version": "3.10.4"
146
+ }
147
+ },
148
+ "nbformat": 4,
149
+ "nbformat_minor": 5
150
+ }
app.py CHANGED
@@ -36,7 +36,7 @@ def identify_language(text):
36
  model = fasttext.load_model(model_full_path)
37
  predictions = model.predict(text, k=1) # e.g., (('__label__eng_Latn',), array([0.81148803]))
38
 
39
- PREFIX_LENGTH = 7 # To strip away '__label__' from language code
40
  language_code = predictions[0][0][PREFIX_LENGTH:]
41
  return language_code
42
 
 
36
  model = fasttext.load_model(model_full_path)
37
  predictions = model.predict(text, k=1) # e.g., (('__label__eng_Latn',), array([0.81148803]))
38
 
39
+ PREFIX_LENGTH = 9 # To strip away '__label__' from language code
40
  language_code = predictions[0][0][PREFIX_LENGTH:]
41
  return language_code
42