Spaces:
Runtime error
Runtime error
Oliver12315
commited on
Gray test for regis.
Browse files
README.md
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
---
|
2 |
-
title:
|
3 |
emoji: 📊
|
4 |
colorFrom: purple
|
5 |
colorTo: red
|
|
|
1 |
---
|
2 |
+
title: Brand Tone of Voice
|
3 |
emoji: 📊
|
4 |
colorFrom: purple
|
5 |
colorTo: red
|
app.py
CHANGED
@@ -5,10 +5,17 @@ import os
|
|
5 |
from datetime import datetime
|
6 |
import re
|
7 |
import json
|
|
|
8 |
|
9 |
persistent_path = "/data"
|
10 |
os.environ['HF_HOME'] = os.path.join(persistent_path, ".huggingface")
|
11 |
user_input_path = os.path.join(persistent_path, 'user.jsonl')
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
|
13 |
examples = []
|
14 |
if os.path.exists("assets/examples.txt"):
|
@@ -46,6 +53,13 @@ def csv_process(csv_file, attr="content"):
|
|
46 |
outputs.append(output_path)
|
47 |
return outputs
|
48 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
49 |
def check_save(fname, lname, cnum, email, oname, position):
|
50 |
errors = []
|
51 |
valid_vars = {}
|
@@ -125,8 +139,6 @@ with gr.Blocks(theme=my_theme, title='Brand_Tone_of_Voice_demo') as demo:
|
|
125 |
</div>
|
126 |
""")
|
127 |
|
128 |
-
|
129 |
-
debug_tb = gr.Textbox(label="Persistent: ", type='text')
|
130 |
with gr.Column(visible=True) as regis:
|
131 |
gr.Markdown("# Welcome to BTV! Please fill out the form below to continue.\nI’m assuming that you mention somewhere that this project/research is conducted by the University of Manchester/AMBS. By ticking this box, I consent to be approached by the research team of the University of Manchester.")
|
132 |
with gr.Column(variant='panel'):
|
@@ -154,7 +166,7 @@ with gr.Blocks(theme=my_theme, title='Brand_Tone_of_Voice_demo') as demo:
|
|
154 |
datatype=["str", "number"],
|
155 |
interactive=False)
|
156 |
with gr.Row():
|
157 |
-
button_ss = gr.Button("Submit", variant="primary"
|
158 |
button_ss.click(fn=single_sentence, inputs=[tbox_input], outputs=[tab_output])
|
159 |
gr.ClearButton([tbox_input, tab_output])
|
160 |
|
@@ -173,7 +185,7 @@ with gr.Blocks(theme=my_theme, title='Brand_Tone_of_Voice_demo') as demo:
|
|
173 |
csv_output = gr.File(label="Predictions:")
|
174 |
|
175 |
with gr.Row():
|
176 |
-
button_cf = gr.Button("Submit", variant="primary"
|
177 |
button_cf.click(fn=csv_process, inputs=[csv_input], outputs=[csv_output])
|
178 |
gr.ClearButton([csv_input, csv_output])
|
179 |
|
@@ -201,6 +213,17 @@ with gr.Blocks(theme=my_theme, title='Brand_Tone_of_Voice_demo') as demo:
|
|
201 |
"""
|
202 |
)
|
203 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
204 |
def submit(*user_input):
|
205 |
res = check_save(*user_input)
|
206 |
if isinstance(res, list):
|
@@ -219,13 +242,12 @@ with gr.Blocks(theme=my_theme, title='Brand_Tone_of_Voice_demo') as demo:
|
|
219 |
return {
|
220 |
mainrow: gr.Row(visible=True),
|
221 |
regis: gr.Row(visible=False),
|
222 |
-
error_box: gr.HTML(visible=False)
|
223 |
-
debug_tb: gr.Textbox(value=json.dumps(res), type='text', visible=True)
|
224 |
}
|
225 |
|
226 |
submit_btn.click(
|
227 |
submit,
|
228 |
[fname_tb, lname_tb, cnum_tb, email_tb, oname_tb, position_tb],
|
229 |
-
[mainrow, regis, error_box
|
230 |
)
|
231 |
demo.launch()
|
|
|
5 |
from datetime import datetime
|
6 |
import re
|
7 |
import json
|
8 |
+
import hashlib
|
9 |
|
10 |
persistent_path = "/data"
|
11 |
os.environ['HF_HOME'] = os.path.join(persistent_path, ".huggingface")
|
12 |
user_input_path = os.path.join(persistent_path, 'user.jsonl')
|
13 |
+
secret = "2fc9ff032e027e8f23bb9fb693234899"
|
14 |
+
|
15 |
+
def get_md5(s):
|
16 |
+
md = hashlib.md5()
|
17 |
+
md.update(s.encode('utf-8'))
|
18 |
+
return md.hexdigest()
|
19 |
|
20 |
examples = []
|
21 |
if os.path.exists("assets/examples.txt"):
|
|
|
53 |
outputs.append(output_path)
|
54 |
return outputs
|
55 |
|
56 |
+
def logfile_query(auth):
|
57 |
+
if get_md5(auth) == secret and os.path.exists(user_input_path):
|
58 |
+
return [user_input_path]
|
59 |
+
else:
|
60 |
+
return None
|
61 |
+
|
62 |
+
|
63 |
def check_save(fname, lname, cnum, email, oname, position):
|
64 |
errors = []
|
65 |
valid_vars = {}
|
|
|
139 |
</div>
|
140 |
""")
|
141 |
|
|
|
|
|
142 |
with gr.Column(visible=True) as regis:
|
143 |
gr.Markdown("# Welcome to BTV! Please fill out the form below to continue.\nI’m assuming that you mention somewhere that this project/research is conducted by the University of Manchester/AMBS. By ticking this box, I consent to be approached by the research team of the University of Manchester.")
|
144 |
with gr.Column(variant='panel'):
|
|
|
166 |
datatype=["str", "number"],
|
167 |
interactive=False)
|
168 |
with gr.Row():
|
169 |
+
button_ss = gr.Button("Submit", variant="primary")
|
170 |
button_ss.click(fn=single_sentence, inputs=[tbox_input], outputs=[tab_output])
|
171 |
gr.ClearButton([tbox_input, tab_output])
|
172 |
|
|
|
185 |
csv_output = gr.File(label="Predictions:")
|
186 |
|
187 |
with gr.Row():
|
188 |
+
button_cf = gr.Button("Submit", variant="primary")
|
189 |
button_cf.click(fn=csv_process, inputs=[csv_input], outputs=[csv_output])
|
190 |
gr.ClearButton([csv_input, csv_output])
|
191 |
|
|
|
213 |
"""
|
214 |
)
|
215 |
|
216 |
+
with gr.Tab("Log File"):
|
217 |
+
with gr.Row():
|
218 |
+
auth_token = gr.Textbox(label="Authentication Tokens: ", info="Enter the key to download persistent stored log information.")
|
219 |
+
log_output = gr.File(label="Log file: ")
|
220 |
+
|
221 |
+
with gr.Row():
|
222 |
+
button_lf = gr.Button("Validate", variant="primary")
|
223 |
+
button_lf.click(fn=logfile_query, inputs=[auth_token], outputs=[log_output])
|
224 |
+
gr.ClearButton([auth_token, log_output])
|
225 |
+
|
226 |
+
|
227 |
def submit(*user_input):
|
228 |
res = check_save(*user_input)
|
229 |
if isinstance(res, list):
|
|
|
242 |
return {
|
243 |
mainrow: gr.Row(visible=True),
|
244 |
regis: gr.Row(visible=False),
|
245 |
+
error_box: gr.HTML(visible=False)
|
|
|
246 |
}
|
247 |
|
248 |
submit_btn.click(
|
249 |
submit,
|
250 |
[fname_tb, lname_tb, cnum_tb, email_tb, oname_tb, position_tb],
|
251 |
+
[mainrow, regis, error_box],
|
252 |
)
|
253 |
demo.launch()
|