Upload 2 files
Browse files- app.py +266 -0
- requirements.txt +8 -0
app.py
ADDED
|
@@ -0,0 +1,266 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"cells": [
|
| 3 |
+
{
|
| 4 |
+
"cell_type": "code",
|
| 5 |
+
"execution_count": 1,
|
| 6 |
+
"id": "1270c596",
|
| 7 |
+
"metadata": {},
|
| 8 |
+
"outputs": [],
|
| 9 |
+
"source": [
|
| 10 |
+
"import pickle\n",
|
| 11 |
+
"from pythainlp.tokenize import word_tokenize\n",
|
| 12 |
+
"import re \n",
|
| 13 |
+
"import pandas as pd\n",
|
| 14 |
+
"filename = r'C:\\Users\\MSI\\Desktop\\fastwork_2022\\subcategory_prediction\\nbsvm_full\\2024_03_12_15_28_vectorizer_and_model.pkl'\n",
|
| 15 |
+
" \n",
|
| 16 |
+
"def sentence_tokenize_proccessing(sentence,engine='newmm'):\n",
|
| 17 |
+
" split_ = word_tokenize(sentence,engine=engine)\n",
|
| 18 |
+
" split_return = []\n",
|
| 19 |
+
" for token in split_:\n",
|
| 20 |
+
" res = re.sub(r'[^a-zก-๙1-9]', '', token.lower())\n",
|
| 21 |
+
" if res != '':\n",
|
| 22 |
+
" split_return.append(res)\n",
|
| 23 |
+
" return split_return\n",
|
| 24 |
+
" \n",
|
| 25 |
+
"with open(filename, 'rb') as f:\n",
|
| 26 |
+
" tfidf_vectorizer, tfidf_model = pickle.load(f)\n",
|
| 27 |
+
" each_class_name = tfidf_model.classes_.tolist()\n",
|
| 28 |
+
"\n",
|
| 29 |
+
"def subcat_predict(word,num=5):\n",
|
| 30 |
+
" word_vector = tfidf_vectorizer.transform([word])\n",
|
| 31 |
+
" dict_word_sc_predict = dict(zip(each_class_name,tfidf_model.predict_proba(word_vector)[0]))\n",
|
| 32 |
+
" sorted_x = sorted(dict_word_sc_predict.items(), key=lambda kv: kv[1],reverse=True)\n",
|
| 33 |
+
" dict_predictions={}\n",
|
| 34 |
+
" for rank_ in range(num):\n",
|
| 35 |
+
" dict_predictions[sorted_x[rank_][0]] = sorted_x[rank_][1]\n",
|
| 36 |
+
" return dict_predictions"
|
| 37 |
+
]
|
| 38 |
+
},
|
| 39 |
+
{
|
| 40 |
+
"cell_type": "code",
|
| 41 |
+
"execution_count": null,
|
| 42 |
+
"id": "1b6094ba",
|
| 43 |
+
"metadata": {},
|
| 44 |
+
"outputs": [],
|
| 45 |
+
"source": []
|
| 46 |
+
},
|
| 47 |
+
{
|
| 48 |
+
"cell_type": "code",
|
| 49 |
+
"execution_count": 4,
|
| 50 |
+
"id": "0a743ade",
|
| 51 |
+
"metadata": {},
|
| 52 |
+
"outputs": [
|
| 53 |
+
{
|
| 54 |
+
"data": {
|
| 55 |
+
"text/plain": [
|
| 56 |
+
"{'Programming & Tech/วิเคราะห์ดาต้า': 0.04640265504474801,\n",
|
| 57 |
+
" 'การตลาดและโฆษณา/ทำแบบสอบถาม': 0.023448823694882836,\n",
|
| 58 |
+
" 'ปรึกษาและแนะนำ/ผู้เชี่ยวชาญให้ความรู้เฉพาะด้าน': 0.0162011877012307,\n",
|
| 59 |
+
" 'Programming & Tech/Website Scraping': 0.016021063565654803,\n",
|
| 60 |
+
" 'เขียนและแปลภาษา/พิมพ์งาน และคีย์ข้อมูล': 0.015659431979139528}"
|
| 61 |
+
]
|
| 62 |
+
},
|
| 63 |
+
"execution_count": 4,
|
| 64 |
+
"metadata": {},
|
| 65 |
+
"output_type": "execute_result"
|
| 66 |
+
}
|
| 67 |
+
],
|
| 68 |
+
"source": [
|
| 69 |
+
"subcat_predict('งานวิจัย วิเคราะห์ข้อมูล โดย SPSS (บทที่ 4)')"
|
| 70 |
+
]
|
| 71 |
+
},
|
| 72 |
+
{
|
| 73 |
+
"cell_type": "code",
|
| 74 |
+
"execution_count": 5,
|
| 75 |
+
"id": "5eee3dbb",
|
| 76 |
+
"metadata": {},
|
| 77 |
+
"outputs": [
|
| 78 |
+
{
|
| 79 |
+
"name": "stdout",
|
| 80 |
+
"output_type": "stream",
|
| 81 |
+
"text": [
|
| 82 |
+
"{'จัดการร้านค้าออนไลน์/แอดมินดูแลเพจ เว็บไซต์ และร้านค้าออนไลน์': 0.07334732692965876, 'การตลาดและโฆษณา/Social Media Ads': 0.024339055174865003, 'การตลาดและโฆษณา/โปรโมทเพจ / เว็บ': 0.019813475956694446}\n"
|
| 83 |
+
]
|
| 84 |
+
}
|
| 85 |
+
],
|
| 86 |
+
"source": [
|
| 87 |
+
"# Provided list of tuples\n",
|
| 88 |
+
"data = [('จัดการร้านค้าออนไลน์/แอดมินดูแลเพจ เว็บไซต์ และร้านค้าออนไลน์', 0.07334732692965876),\n",
|
| 89 |
+
" ('การตลาดและโฆษณา/Social Media Ads', 0.024339055174865003),\n",
|
| 90 |
+
" ('การตลาดและโฆษณา/โปรโมทเพจ / เว็บ', 0.019813475956694446)]\n",
|
| 91 |
+
"\n",
|
| 92 |
+
"# Create an empty dictionary\n",
|
| 93 |
+
"subcategory_probs = {}\n",
|
| 94 |
+
"\n",
|
| 95 |
+
"# Loop through each tuple in the list and add it to the dictionary\n",
|
| 96 |
+
"# Using unpacking for clarity\n",
|
| 97 |
+
"for subcategory, probability in data:\n",
|
| 98 |
+
" subcategory_probs[subcategory] = probability\n",
|
| 99 |
+
"\n",
|
| 100 |
+
"print(subcategory_probs)"
|
| 101 |
+
]
|
| 102 |
+
},
|
| 103 |
+
{
|
| 104 |
+
"cell_type": "code",
|
| 105 |
+
"execution_count": 6,
|
| 106 |
+
"id": "c24da9e9",
|
| 107 |
+
"metadata": {},
|
| 108 |
+
"outputs": [
|
| 109 |
+
{
|
| 110 |
+
"name": "stderr",
|
| 111 |
+
"output_type": "stream",
|
| 112 |
+
"text": [
|
| 113 |
+
"C:\\Users\\MSI\\anaconda3\\envs\\nlp\\lib\\site-packages\\gradio\\outputs.py:196: UserWarning: Usage of gradio.outputs is deprecated, and will not be supported in the future, please import your components from gradio.components\n",
|
| 114 |
+
" warnings.warn(\n",
|
| 115 |
+
"C:\\Users\\MSI\\anaconda3\\envs\\nlp\\lib\\site-packages\\gradio\\deprecation.py:40: UserWarning: The 'type' parameter has been deprecated. Use the Number component instead.\n",
|
| 116 |
+
" warnings.warn(value)\n"
|
| 117 |
+
]
|
| 118 |
+
},
|
| 119 |
+
{
|
| 120 |
+
"name": "stdout",
|
| 121 |
+
"output_type": "stream",
|
| 122 |
+
"text": [
|
| 123 |
+
"Running on local URL: http://127.0.0.1:7860/\n"
|
| 124 |
+
]
|
| 125 |
+
},
|
| 126 |
+
{
|
| 127 |
+
"name": "stderr",
|
| 128 |
+
"output_type": "stream",
|
| 129 |
+
"text": [
|
| 130 |
+
"ERROR:root:Internal Python error in the inspect module.\n",
|
| 131 |
+
"Below is the traceback from this internal error.\n",
|
| 132 |
+
"\n"
|
| 133 |
+
]
|
| 134 |
+
},
|
| 135 |
+
{
|
| 136 |
+
"name": "stdout",
|
| 137 |
+
"output_type": "stream",
|
| 138 |
+
"text": [
|
| 139 |
+
"*** Failed to connect to ec2.gradio.app:22: [WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond\n",
|
| 140 |
+
"Traceback (most recent call last):\n",
|
| 141 |
+
" File \"C:\\Users\\MSI\\anaconda3\\envs\\nlp\\lib\\site-packages\\gradio\\tunneling.py\", line 74, in create_tunnel\n",
|
| 142 |
+
" client.connect(\n",
|
| 143 |
+
" File \"C:\\Users\\MSI\\anaconda3\\envs\\nlp\\lib\\site-packages\\paramiko\\client.py\", line 349, in connect\n",
|
| 144 |
+
" retry_on_signal(lambda: sock.connect(addr))\n",
|
| 145 |
+
" File \"C:\\Users\\MSI\\anaconda3\\envs\\nlp\\lib\\site-packages\\paramiko\\util.py\", line 279, in retry_on_signal\n",
|
| 146 |
+
" return function()\n",
|
| 147 |
+
" File \"C:\\Users\\MSI\\anaconda3\\envs\\nlp\\lib\\site-packages\\paramiko\\client.py\", line 349, in <lambda>\n",
|
| 148 |
+
" retry_on_signal(lambda: sock.connect(addr))\n",
|
| 149 |
+
"TimeoutError: [WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond\n",
|
| 150 |
+
"\n",
|
| 151 |
+
"During handling of the above exception, another exception occurred:\n",
|
| 152 |
+
"\n",
|
| 153 |
+
"Traceback (most recent call last):\n",
|
| 154 |
+
" File \"C:\\Users\\MSI\\anaconda3\\envs\\nlp\\lib\\site-packages\\IPython\\core\\interactiveshell.py\", line 3553, in run_code\n",
|
| 155 |
+
" exec(code_obj, self.user_global_ns, self.user_ns)\n",
|
| 156 |
+
" File \"C:\\Users\\MSI\\AppData\\Local\\Temp\\ipykernel_14804\\1549719439.py\", line 18, in <cell line: 18>\n",
|
| 157 |
+
" demo.launch(share=True)\n",
|
| 158 |
+
" File \"C:\\Users\\MSI\\anaconda3\\envs\\nlp\\lib\\site-packages\\gradio\\blocks.py\", line 864, in launch\n",
|
| 159 |
+
" share_url = networking.setup_tunnel(self.server_port, None)\n",
|
| 160 |
+
" File \"C:\\Users\\MSI\\anaconda3\\envs\\nlp\\lib\\site-packages\\gradio\\networking.py\", line 176, in setup_tunnel\n",
|
| 161 |
+
" return create_tunnel(payload, LOCALHOST_NAME, local_server_port)\n",
|
| 162 |
+
" File \"C:\\Users\\MSI\\anaconda3\\envs\\nlp\\lib\\site-packages\\gradio\\tunneling.py\", line 82, in create_tunnel\n",
|
| 163 |
+
" sys.exit(1)\n",
|
| 164 |
+
"SystemExit: 1\n",
|
| 165 |
+
"\n",
|
| 166 |
+
"During handling of the above exception, another exception occurred:\n",
|
| 167 |
+
"\n",
|
| 168 |
+
"Traceback (most recent call last):\n",
|
| 169 |
+
" File \"C:\\Users\\MSI\\anaconda3\\envs\\nlp\\lib\\site-packages\\IPython\\core\\ultratb.py\", line 1101, in get_records\n",
|
| 170 |
+
" return _fixed_getinnerframes(etb, number_of_lines_of_context, tb_offset)\n",
|
| 171 |
+
" File \"C:\\Users\\MSI\\anaconda3\\envs\\nlp\\lib\\site-packages\\IPython\\core\\ultratb.py\", line 248, in wrapped\n",
|
| 172 |
+
" return f(*args, **kwargs)\n",
|
| 173 |
+
" File \"C:\\Users\\MSI\\anaconda3\\envs\\nlp\\lib\\site-packages\\IPython\\core\\ultratb.py\", line 281, in _fixed_getinnerframes\n",
|
| 174 |
+
" records = fix_frame_records_filenames(inspect.getinnerframes(etb, context))\n",
|
| 175 |
+
" File \"C:\\Users\\MSI\\anaconda3\\envs\\nlp\\lib\\inspect.py\", line 1515, in getinnerframes\n",
|
| 176 |
+
" frameinfo = (tb.tb_frame,) + getframeinfo(tb, context)\n",
|
| 177 |
+
"AttributeError: 'tuple' object has no attribute 'tb_frame'\n"
|
| 178 |
+
]
|
| 179 |
+
},
|
| 180 |
+
{
|
| 181 |
+
"ename": "TypeError",
|
| 182 |
+
"evalue": "object of type 'NoneType' has no len()",
|
| 183 |
+
"output_type": "error",
|
| 184 |
+
"traceback": [
|
| 185 |
+
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
|
| 186 |
+
"\u001b[1;31mTimeoutError\u001b[0m Traceback (most recent call last)",
|
| 187 |
+
"\u001b[1;32m~\\anaconda3\\envs\\nlp\\lib\\site-packages\\gradio\\tunneling.py\u001b[0m in \u001b[0;36mcreate_tunnel\u001b[1;34m(payload, local_server, local_server_port)\u001b[0m\n\u001b[0;32m 73\u001b[0m \u001b[0mwarnings\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0msimplefilter\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"ignore\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 74\u001b[1;33m client.connect(\n\u001b[0m\u001b[0;32m 75\u001b[0m \u001b[0mhostname\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mpayload\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m\"host\"\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
|
| 188 |
+
"\u001b[1;32m~\\anaconda3\\envs\\nlp\\lib\\site-packages\\paramiko\\client.py\u001b[0m in \u001b[0;36mconnect\u001b[1;34m(self, hostname, port, username, password, pkey, key_filename, timeout, allow_agent, look_for_keys, compress, sock, gss_auth, gss_kex, gss_deleg_creds, gss_host, banner_timeout, auth_timeout, gss_trust_dns, passphrase, disabled_algorithms)\u001b[0m\n\u001b[0;32m 348\u001b[0m \u001b[1;32mpass\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 349\u001b[1;33m \u001b[0mretry_on_signal\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;32mlambda\u001b[0m\u001b[1;33m:\u001b[0m \u001b[0msock\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mconnect\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0maddr\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 350\u001b[0m \u001b[1;31m# Break out of the loop on success\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
|
| 189 |
+
"\u001b[1;32m~\\anaconda3\\envs\\nlp\\lib\\site-packages\\paramiko\\util.py\u001b[0m in \u001b[0;36mretry_on_signal\u001b[1;34m(function)\u001b[0m\n\u001b[0;32m 278\u001b[0m \u001b[1;32mtry\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 279\u001b[1;33m \u001b[1;32mreturn\u001b[0m \u001b[0mfunction\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 280\u001b[0m \u001b[1;32mexcept\u001b[0m \u001b[0mEnvironmentError\u001b[0m \u001b[1;32mas\u001b[0m \u001b[0me\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
|
| 190 |
+
"\u001b[1;32m~\\anaconda3\\envs\\nlp\\lib\\site-packages\\paramiko\\client.py\u001b[0m in \u001b[0;36m<lambda>\u001b[1;34m()\u001b[0m\n\u001b[0;32m 348\u001b[0m \u001b[1;32mpass\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 349\u001b[1;33m \u001b[0mretry_on_signal\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;32mlambda\u001b[0m\u001b[1;33m:\u001b[0m \u001b[0msock\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mconnect\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0maddr\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 350\u001b[0m \u001b[1;31m# Break out of the loop on success\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
|
| 191 |
+
"\u001b[1;31mTimeoutError\u001b[0m: [WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond",
|
| 192 |
+
"\nDuring handling of the above exception, another exception occurred:\n",
|
| 193 |
+
"\u001b[1;31mSystemExit\u001b[0m Traceback (most recent call last)",
|
| 194 |
+
" \u001b[1;31m[... skipping hidden 1 frame]\u001b[0m\n",
|
| 195 |
+
"\u001b[1;32m~\\AppData\\Local\\Temp\\ipykernel_14804\\1549719439.py\u001b[0m in \u001b[0;36m<cell line: 18>\u001b[1;34m()\u001b[0m\n\u001b[0;32m 17\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 18\u001b[1;33m \u001b[0mdemo\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mlaunch\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mshare\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;32mTrue\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
|
| 196 |
+
"\u001b[1;32m~\\anaconda3\\envs\\nlp\\lib\\site-packages\\gradio\\blocks.py\u001b[0m in \u001b[0;36mlaunch\u001b[1;34m(self, inline, inbrowser, share, debug, enable_queue, max_threads, auth, auth_message, prevent_thread_lock, show_error, server_name, server_port, show_tips, height, width, encrypt, favicon_path, ssl_keyfile, ssl_certfile, ssl_keyfile_password, quiet, _frontend)\u001b[0m\n\u001b[0;32m 863\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mshare_url\u001b[0m \u001b[1;32mis\u001b[0m \u001b[1;32mNone\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 864\u001b[1;33m \u001b[0mshare_url\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mnetworking\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0msetup_tunnel\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mserver_port\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;32mNone\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 865\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mshare_url\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mshare_url\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
|
| 197 |
+
"\u001b[1;32m~\\anaconda3\\envs\\nlp\\lib\\site-packages\\gradio\\networking.py\u001b[0m in \u001b[0;36msetup_tunnel\u001b[1;34m(local_server_port, endpoint)\u001b[0m\n\u001b[0;32m 175\u001b[0m \u001b[0mpayload\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mresponse\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mjson\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m0\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 176\u001b[1;33m \u001b[1;32mreturn\u001b[0m \u001b[0mcreate_tunnel\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mpayload\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mLOCALHOST_NAME\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mlocal_server_port\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 177\u001b[0m \u001b[1;32mexcept\u001b[0m \u001b[0mException\u001b[0m \u001b[1;32mas\u001b[0m \u001b[0me\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
|
| 198 |
+
"\u001b[1;32m~\\anaconda3\\envs\\nlp\\lib\\site-packages\\gradio\\tunneling.py\u001b[0m in \u001b[0;36mcreate_tunnel\u001b[1;34m(payload, local_server, local_server_port)\u001b[0m\n\u001b[0;32m 81\u001b[0m \u001b[0mprint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34mf'*** Failed to connect to {payload[\"host\"]}:{payload[\"port\"]}: {e}'\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 82\u001b[1;33m \u001b[0msys\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mexit\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;36m1\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 83\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n",
|
| 199 |
+
"\u001b[1;31mSystemExit\u001b[0m: 1",
|
| 200 |
+
"\nDuring handling of the above exception, another exception occurred:\n",
|
| 201 |
+
"\u001b[1;31mTypeError\u001b[0m Traceback (most recent call last)",
|
| 202 |
+
" \u001b[1;31m[... skipping hidden 1 frame]\u001b[0m\n",
|
| 203 |
+
"\u001b[1;32m~\\anaconda3\\envs\\nlp\\lib\\site-packages\\IPython\\core\\interactiveshell.py\u001b[0m in \u001b[0;36mshowtraceback\u001b[1;34m(self, exc_tuple, filename, tb_offset, exception_only, running_compiled_code)\u001b[0m\n\u001b[0;32m 2090\u001b[0m stb = ['An exception has occurred, use %tb to see '\n\u001b[0;32m 2091\u001b[0m 'the full traceback.\\n']\n\u001b[1;32m-> 2092\u001b[1;33m stb.extend(self.InteractiveTB.get_exception_only(etype,\n\u001b[0m\u001b[0;32m 2093\u001b[0m value))\n\u001b[0;32m 2094\u001b[0m \u001b[1;32melse\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
|
| 204 |
+
"\u001b[1;32m~\\anaconda3\\envs\\nlp\\lib\\site-packages\\IPython\\core\\ultratb.py\u001b[0m in \u001b[0;36mget_exception_only\u001b[1;34m(self, etype, value)\u001b[0m\n\u001b[0;32m 752\u001b[0m \u001b[0mvalue\u001b[0m \u001b[1;33m:\u001b[0m \u001b[0mexception\u001b[0m \u001b[0mvalue\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 753\u001b[0m \"\"\"\n\u001b[1;32m--> 754\u001b[1;33m \u001b[1;32mreturn\u001b[0m \u001b[0mListTB\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mstructured_traceback\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0metype\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mvalue\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 755\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 756\u001b[0m \u001b[1;32mdef\u001b[0m \u001b[0mshow_exception_only\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0metype\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mevalue\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
|
| 205 |
+
"\u001b[1;32m~\\anaconda3\\envs\\nlp\\lib\\site-packages\\IPython\\core\\ultratb.py\u001b[0m in \u001b[0;36mstructured_traceback\u001b[1;34m(self, etype, evalue, etb, tb_offset, context)\u001b[0m\n\u001b[0;32m 627\u001b[0m \u001b[0mchained_exceptions_tb_offset\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;36m0\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 628\u001b[0m out_list = (\n\u001b[1;32m--> 629\u001b[1;33m self.structured_traceback(\n\u001b[0m\u001b[0;32m 630\u001b[0m \u001b[0metype\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mevalue\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m(\u001b[0m\u001b[0metb\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mchained_exc_ids\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 631\u001b[0m chained_exceptions_tb_offset, context)\n",
|
| 206 |
+
"\u001b[1;32m~\\anaconda3\\envs\\nlp\\lib\\site-packages\\IPython\\core\\ultratb.py\u001b[0m in \u001b[0;36mstructured_traceback\u001b[1;34m(self, etype, value, tb, tb_offset, number_of_lines_of_context)\u001b[0m\n\u001b[0;32m 1365\u001b[0m \u001b[1;32melse\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 1366\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mtb\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mtb\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m-> 1367\u001b[1;33m return FormattedTB.structured_traceback(\n\u001b[0m\u001b[0;32m 1368\u001b[0m self, etype, value, tb, tb_offset, number_of_lines_of_context)\n\u001b[0;32m 1369\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n",
|
| 207 |
+
"\u001b[1;32m~\\anaconda3\\envs\\nlp\\lib\\site-packages\\IPython\\core\\ultratb.py\u001b[0m in \u001b[0;36mstructured_traceback\u001b[1;34m(self, etype, value, tb, tb_offset, number_of_lines_of_context)\u001b[0m\n\u001b[0;32m 1265\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mmode\u001b[0m \u001b[1;32min\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mverbose_modes\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 1266\u001b[0m \u001b[1;31m# Verbose modes need a full traceback\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m-> 1267\u001b[1;33m return VerboseTB.structured_traceback(\n\u001b[0m\u001b[0;32m 1268\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0metype\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mvalue\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mtb\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mtb_offset\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mnumber_of_lines_of_context\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 1269\u001b[0m )\n",
|
| 208 |
+
"\u001b[1;32m~\\anaconda3\\envs\\nlp\\lib\\site-packages\\IPython\\core\\ultratb.py\u001b[0m in \u001b[0;36mstructured_traceback\u001b[1;34m(self, etype, evalue, etb, tb_offset, number_of_lines_of_context)\u001b[0m\n\u001b[0;32m 1122\u001b[0m \u001b[1;34m\"\"\"Return a nice text document describing the traceback.\"\"\"\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 1123\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m-> 1124\u001b[1;33m formatted_exception = self.format_exception_as_a_whole(etype, evalue, etb, number_of_lines_of_context,\n\u001b[0m\u001b[0;32m 1125\u001b[0m tb_offset)\n\u001b[0;32m 1126\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n",
|
| 209 |
+
"\u001b[1;32m~\\anaconda3\\envs\\nlp\\lib\\site-packages\\IPython\\core\\ultratb.py\u001b[0m in \u001b[0;36mformat_exception_as_a_whole\u001b[1;34m(self, etype, evalue, etb, number_of_lines_of_context, tb_offset)\u001b[0m\n\u001b[0;32m 1080\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 1081\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m-> 1082\u001b[1;33m \u001b[0mlast_unique\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mrecursion_repeat\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mfind_recursion\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0morig_etype\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mevalue\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mrecords\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 1083\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 1084\u001b[0m \u001b[0mframes\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mformat_records\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mrecords\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mlast_unique\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mrecursion_repeat\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
|
| 210 |
+
"\u001b[1;32m~\\anaconda3\\envs\\nlp\\lib\\site-packages\\IPython\\core\\ultratb.py\u001b[0m in \u001b[0;36mfind_recursion\u001b[1;34m(etype, value, records)\u001b[0m\n\u001b[0;32m 380\u001b[0m \u001b[1;31m# first frame (from in to out) that looks different.\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 381\u001b[0m \u001b[1;32mif\u001b[0m \u001b[1;32mnot\u001b[0m \u001b[0mis_recursion_error\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0metype\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mvalue\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mrecords\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 382\u001b[1;33m \u001b[1;32mreturn\u001b[0m \u001b[0mlen\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mrecords\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;36m0\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 383\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 384\u001b[0m \u001b[1;31m# Select filename, lineno, func_name to track frames with\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
|
| 211 |
+
"\u001b[1;31mTypeError\u001b[0m: object of type 'NoneType' has no len()"
|
| 212 |
+
]
|
| 213 |
+
}
|
| 214 |
+
],
|
| 215 |
+
"source": [
|
| 216 |
+
"# In[259] test 2 \n",
|
| 217 |
+
"import gradio as gr\n",
|
| 218 |
+
"demo = gr.Blocks()\n",
|
| 219 |
+
"\n",
|
| 220 |
+
"with demo:\n",
|
| 221 |
+
" with gr.Row():\n",
|
| 222 |
+
" with gr.Column():\n",
|
| 223 |
+
"\n",
|
| 224 |
+
" gr.Markdown(\"มาให้โมเดลทำนาย subcat จากชื่อ Product กันจ้า\")\n",
|
| 225 |
+
" with gr.Row():\n",
|
| 226 |
+
" \n",
|
| 227 |
+
" text_input = gr.Textbox(label='พิมพ์ชื่อ product แล้วกด Predict! ได้เลยจ้า')\n",
|
| 228 |
+
" predict_button = gr.Button(\"Predict!\")\n",
|
| 229 |
+
" \n",
|
| 230 |
+
" predict_button.click(subcat_predict, inputs=text_input, \n",
|
| 231 |
+
" outputs = gr.outputs.Label())\n",
|
| 232 |
+
"\n",
|
| 233 |
+
"demo.launch(share=True)"
|
| 234 |
+
]
|
| 235 |
+
},
|
| 236 |
+
{
|
| 237 |
+
"cell_type": "code",
|
| 238 |
+
"execution_count": null,
|
| 239 |
+
"id": "2422e7b9",
|
| 240 |
+
"metadata": {},
|
| 241 |
+
"outputs": [],
|
| 242 |
+
"source": []
|
| 243 |
+
}
|
| 244 |
+
],
|
| 245 |
+
"metadata": {
|
| 246 |
+
"kernelspec": {
|
| 247 |
+
"display_name": "Python 3 (ipykernel)",
|
| 248 |
+
"language": "python",
|
| 249 |
+
"name": "python3"
|
| 250 |
+
},
|
| 251 |
+
"language_info": {
|
| 252 |
+
"codemirror_mode": {
|
| 253 |
+
"name": "ipython",
|
| 254 |
+
"version": 3
|
| 255 |
+
},
|
| 256 |
+
"file_extension": ".py",
|
| 257 |
+
"mimetype": "text/x-python",
|
| 258 |
+
"name": "python",
|
| 259 |
+
"nbconvert_exporter": "python",
|
| 260 |
+
"pygments_lexer": "ipython3",
|
| 261 |
+
"version": "3.8.8"
|
| 262 |
+
}
|
| 263 |
+
},
|
| 264 |
+
"nbformat": 4,
|
| 265 |
+
"nbformat_minor": 5
|
| 266 |
+
}
|
requirements.txt
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
numpy==1.19.5
|
| 2 |
+
pandas==1.4.3
|
| 3 |
+
pythainlp==3.0.8
|
| 4 |
+
scikit-learn==0.23.2
|
| 5 |
+
ipython==7.34.0
|
| 6 |
+
ipython-genutils==0.2.0
|
| 7 |
+
ipywidgets==7.7.1
|
| 8 |
+
pygsheets
|