Spaces:
Runtime error
Runtime error
Commit ·
a600a71
1
Parent(s): 0c22273
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,13 +2,13 @@
|
|
| 2 |
# coding: utf-8
|
| 3 |
import os
|
| 4 |
import pygsheets
|
| 5 |
-
print(os.environ['py_api'])
|
| 6 |
-
import json
|
| 7 |
-
stud_obj = json.loads(str(os.environ['py_api']))
|
| 8 |
|
| 9 |
-
gc = pygsheets.authorize(client_secret= stud_obj )
|
| 10 |
#gc = pygsheets.authorize(client_secret= os.environ['py_api'])
|
| 11 |
-
|
| 12 |
|
| 13 |
# ## Import Libs
|
| 14 |
|
|
@@ -36,13 +36,10 @@ print('Token example:',word_tokenize(title[rand:rand+1].values[0],engine='longes
|
|
| 36 |
# In[234]:
|
| 37 |
|
| 38 |
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
except:
|
| 44 |
-
wk = sh.add_worksheet(tab_name)
|
| 45 |
-
wk.set_dataframe(df,'A1')
|
| 46 |
|
| 47 |
def token_processing(token):
|
| 48 |
res = re.sub(r'[^a-zก-๙1-9]', '', token.lower())
|
|
@@ -146,20 +143,16 @@ def subcat_predict(word):
|
|
| 146 |
return dict(zip(pr.loc[:2,'predict'],pr.loc[:2,'prob']))
|
| 147 |
log = []
|
| 148 |
log_correct= []
|
| 149 |
-
|
| 150 |
-
num_2 = 0
|
| 151 |
def correct_number1(number):
|
| 152 |
-
global num
|
| 153 |
log.append([text_,'1-right',pr.loc[0,'predict'],pr.loc[0,'prob']])
|
| 154 |
-
|
| 155 |
-
pygsheets_df(pd.DataFrame(log,columns=['title','label','sc_pred','prob']))
|
| 156 |
return 'thank for teaching the model'
|
| 157 |
|
| 158 |
def correct_number2(number):
|
| 159 |
-
global num
|
| 160 |
log.append([text_,'1-wrong',pr.loc[0,'predict'],pr.loc[0,'prob']])
|
| 161 |
log.append([text_,'2-right',pr.loc[1,'predict'],pr.loc[1,'prob']])
|
| 162 |
-
|
| 163 |
return 'thank for teaching the model'
|
| 164 |
|
| 165 |
def correct_number3(number):
|
|
@@ -168,20 +161,18 @@ def correct_number3(number):
|
|
| 168 |
log.append([text_,'2-wrong',pr.loc[1,'predict'],pr.loc[1,'prob']])
|
| 169 |
log.append([text_,'3-right',pr.loc[2,'predict'],pr.loc[2,'prob']])
|
| 170 |
|
| 171 |
-
|
| 172 |
return 'thank for teaching the model'
|
| 173 |
|
| 174 |
def feedback(correction_input,text_input):
|
| 175 |
-
global num_2
|
| 176 |
log.append([text_,'1-wrong',pr.loc[0,'predict'],pr.loc[0,'prob']])
|
| 177 |
log.append([text_,'2-wrong',pr.loc[1,'predict'],pr.loc[1,'prob']])
|
| 178 |
log.append([text_,'3-wrong',pr.loc[2,'predict'],pr.loc[2,'prob']])
|
| 179 |
log_correct.append([text_,'feedback',pr.loc[0,'predict'],pr.loc[0,'prob'],correction_input])
|
| 180 |
-
|
| 181 |
-
|
| 182 |
return 'thank for teaching the model'
|
| 183 |
with demo:
|
| 184 |
-
|
| 185 |
with gr.Row():
|
| 186 |
with gr.Column():
|
| 187 |
|
|
|
|
| 2 |
# coding: utf-8
|
| 3 |
import os
|
| 4 |
import pygsheets
|
| 5 |
+
#print(os.environ['py_api'])
|
| 6 |
+
#import json
|
| 7 |
+
#stud_obj = json.loads(str(os.environ['py_api']))
|
| 8 |
|
| 9 |
+
#gc = pygsheets.authorize(client_secret= stud_obj )
|
| 10 |
#gc = pygsheets.authorize(client_secret= os.environ['py_api'])
|
| 11 |
+
gc = pygsheets.authorize(service_account_env_var = 'service_acc')
|
| 12 |
|
| 13 |
# ## Import Libs
|
| 14 |
|
|
|
|
| 36 |
# In[234]:
|
| 37 |
|
| 38 |
|
| 39 |
+
|
| 40 |
+
sh = gc.open('Subcategory Prediction')
|
| 41 |
+
wk = sh.worksheet_by_title('huggingface-test')
|
| 42 |
+
wk2 = sh.worksheet_by_title('correction')
|
|
|
|
|
|
|
|
|
|
| 43 |
|
| 44 |
def token_processing(token):
|
| 45 |
res = re.sub(r'[^a-zก-๙1-9]', '', token.lower())
|
|
|
|
| 143 |
return dict(zip(pr.loc[:2,'predict'],pr.loc[:2,'prob']))
|
| 144 |
log = []
|
| 145 |
log_correct= []
|
| 146 |
+
|
|
|
|
| 147 |
def correct_number1(number):
|
|
|
|
| 148 |
log.append([text_,'1-right',pr.loc[0,'predict'],pr.loc[0,'prob']])
|
| 149 |
+
wk.set_dataframe(pd.DataFrame(log,columns=['title','label','sc_pred','prob']),'A1')
|
|
|
|
| 150 |
return 'thank for teaching the model'
|
| 151 |
|
| 152 |
def correct_number2(number):
|
|
|
|
| 153 |
log.append([text_,'1-wrong',pr.loc[0,'predict'],pr.loc[0,'prob']])
|
| 154 |
log.append([text_,'2-right',pr.loc[1,'predict'],pr.loc[1,'prob']])
|
| 155 |
+
wk.set_dataframe(pd.DataFrame(log,columns=['title','label','sc_pred','prob']),'A1')
|
| 156 |
return 'thank for teaching the model'
|
| 157 |
|
| 158 |
def correct_number3(number):
|
|
|
|
| 161 |
log.append([text_,'2-wrong',pr.loc[1,'predict'],pr.loc[1,'prob']])
|
| 162 |
log.append([text_,'3-right',pr.loc[2,'predict'],pr.loc[2,'prob']])
|
| 163 |
|
| 164 |
+
wk.set_dataframe(pd.DataFrame(log,columns=['title','label','sc_pred','prob']),'A1')
|
| 165 |
return 'thank for teaching the model'
|
| 166 |
|
| 167 |
def feedback(correction_input,text_input):
|
|
|
|
| 168 |
log.append([text_,'1-wrong',pr.loc[0,'predict'],pr.loc[0,'prob']])
|
| 169 |
log.append([text_,'2-wrong',pr.loc[1,'predict'],pr.loc[1,'prob']])
|
| 170 |
log.append([text_,'3-wrong',pr.loc[2,'predict'],pr.loc[2,'prob']])
|
| 171 |
log_correct.append([text_,'feedback',pr.loc[0,'predict'],pr.loc[0,'prob'],correction_input])
|
| 172 |
+
wk.set_dataframe(pd.DataFrame(log,columns=['title','label','sc_pred','prob']),'A1')
|
| 173 |
+
wk2.set_dataframe(pd.DataFrame(log_correct,columns=['title','label','sc_pred','prob','real_sc']),'A1')
|
| 174 |
return 'thank for teaching the model'
|
| 175 |
with demo:
|
|
|
|
| 176 |
with gr.Row():
|
| 177 |
with gr.Column():
|
| 178 |
|