fixed bug for updating dashboard and added preliminary logs
Browse files
app.py
CHANGED
@@ -17,6 +17,7 @@ import plotly.graph_objects as go
|
|
17 |
import boto3
|
18 |
import json
|
19 |
from plotly.subplots import make_subplots
|
|
|
20 |
|
21 |
fs = fsspec.filesystem(
|
22 |
's3',
|
@@ -37,6 +38,42 @@ EMAIL_PATH = f"s3://{os.getenv('AWS_BUCKET_NAME')}/{os.getenv('EMAILS_KEY')}"
|
|
37 |
TEMP_DIR = f"s3://{os.getenv('AWS_BUCKET_NAME')}/{os.getenv('AUDIOS_KEY')}"
|
38 |
CREATE_TASK_URL = os.getenv("CREATE_TASK_URL")
|
39 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
40 |
|
41 |
def write_email(email):
|
42 |
if fs.exists(EMAIL_PATH):
|
@@ -96,8 +133,6 @@ class ResultWriter:
|
|
96 |
|
97 |
send_task(payload)
|
98 |
|
99 |
-
|
100 |
-
|
101 |
def decode_audio_array(base64_string):
|
102 |
bytes_data = base64.b64decode(base64_string)
|
103 |
|
@@ -113,7 +148,9 @@ def send_task(payload):
|
|
113 |
response = requests.post(CREATE_TASK_URL,json=payload,headers=header)
|
114 |
try:
|
115 |
response = response.json()
|
116 |
-
except Exception:
|
|
|
|
|
117 |
return "error please try again"
|
118 |
|
119 |
if payload["task"] == "transcribe_with_fastapi":
|
@@ -160,21 +197,21 @@ def call_function(model_name):
|
|
160 |
return transcript
|
161 |
|
162 |
def transcribe_audio():
|
|
|
|
|
|
|
163 |
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
st.session_state.option_1_model_name = model1_name
|
168 |
-
st.session_state.option_2_model_name = model2_name
|
169 |
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
|
176 |
-
|
177 |
-
|
178 |
|
179 |
|
180 |
return transcript1, transcript2
|
@@ -429,20 +466,23 @@ def create_metric_container(label, value, full_name=None):
|
|
429 |
st.markdown(f"<h3 style='margin-top: 0;'>{value}</h3>", unsafe_allow_html=True)
|
430 |
|
431 |
def on_refresh_click():
|
432 |
-
with
|
433 |
-
|
|
|
434 |
|
435 |
-
|
436 |
-
|
437 |
-
|
438 |
-
|
439 |
-
|
|
|
440 |
|
441 |
-
|
442 |
-
|
443 |
-
|
444 |
-
|
445 |
-
|
|
|
446 |
|
447 |
def dashboard():
|
448 |
st.title('Model Arena Scoreboard')
|
@@ -451,17 +491,13 @@ def dashboard():
|
|
451 |
with fs.open(SAVE_PATH, 'rb') as f:
|
452 |
st.session_state.df = pd.read_csv(f)
|
453 |
if "elo_json" not in st.session_state:
|
454 |
-
|
455 |
-
|
456 |
-
|
457 |
-
except Exception:
|
458 |
-
st.session_state.elo_json = None
|
459 |
if "elo_df" not in st.session_state:
|
460 |
-
|
461 |
-
|
462 |
-
|
463 |
-
except Exception:
|
464 |
-
st.session_state.elo_df = None
|
465 |
|
466 |
st.button("Refresh",on_click=on_refresh_click)
|
467 |
|
@@ -527,7 +563,7 @@ def dashboard():
|
|
527 |
appearance_chart = create_appearance_chart(metrics)
|
528 |
st.plotly_chart(appearance_chart, use_container_width=True)
|
529 |
|
530 |
-
if st.session_state.elo_json and st.session_state.elo_df:
|
531 |
st.header('Elo Ratings')
|
532 |
st.dataframe(pd.DataFrame(st.session_state.elo_json,index=[0]),use_container_width=True)
|
533 |
elo_progression_chart = create_elo_chart(st.session_state.elo_df)
|
@@ -714,7 +750,7 @@ def main():
|
|
714 |
st.button("Prefer None",on_click=on_option_none_click)
|
715 |
|
716 |
with scoreboard:
|
717 |
-
if st.session_state.logged_in:
|
718 |
dashboard()
|
719 |
else:
|
720 |
with st.form("contact_us_form"):
|
@@ -741,4 +777,5 @@ def main():
|
|
741 |
with about_tab:
|
742 |
about()
|
743 |
|
|
|
744 |
main()
|
|
|
17 |
import boto3
|
18 |
import json
|
19 |
from plotly.subplots import make_subplots
|
20 |
+
from logger import logger
|
21 |
|
22 |
fs = fsspec.filesystem(
|
23 |
's3',
|
|
|
38 |
TEMP_DIR = f"s3://{os.getenv('AWS_BUCKET_NAME')}/{os.getenv('AUDIOS_KEY')}"
|
39 |
CREATE_TASK_URL = os.getenv("CREATE_TASK_URL")
|
40 |
|
41 |
+
def create_files():
|
42 |
+
if not fs.exists(SAVE_PATH):
|
43 |
+
logger.info("Creating save file")
|
44 |
+
with fs.open(SAVE_PATH, 'wb') as f:
|
45 |
+
headers = [
|
46 |
+
'email',
|
47 |
+
'path',
|
48 |
+
'Ori Apex_score', 'Ori Apex XT_score', 'deepgram_score', 'Ori Swift_score', 'Ori Prime_score',
|
49 |
+
'Ori Apex_appearance', 'Ori Apex XT_appearance', 'deepgram_appearance', 'Ori Swift_appearance', 'Ori Prime_appearance',
|
50 |
+
'Ori Apex_duration', 'Ori Apex XT_duration', 'deepgram_duration', 'Ori Swift_duration', 'Ori Prime_duration','azure_score','azure_appearance','azure_duration'
|
51 |
+
]
|
52 |
+
df = pd.DataFrame(columns=headers)
|
53 |
+
df.to_csv(f, index=False)
|
54 |
+
|
55 |
+
if not fs.exists(ELO_JSON_PATH):
|
56 |
+
logger.info("Creating Elo json file")
|
57 |
+
with fs.open(ELO_JSON_PATH, 'w') as f:
|
58 |
+
models = ['Ori Apex', 'Ori Apex XT', 'deepgram', 'Ori Swift', 'Ori Prime', 'azure']
|
59 |
+
models = {model: 1000 for model in models}
|
60 |
+
json.dump(models, f)
|
61 |
+
|
62 |
+
if not fs.exists(ELO_CSV_PATH):
|
63 |
+
logger.info("Creating Elo csv file")
|
64 |
+
with fs.open(ELO_CSV_PATH, 'wb') as f:
|
65 |
+
models = ['Ori Apex', 'Ori Apex XT', 'deepgram', 'Ori Swift', 'Ori Prime', 'azure']
|
66 |
+
models = {k:1000 for k in models}
|
67 |
+
df = pd.DataFrame(models,index=[0])
|
68 |
+
df.to_csv(f, index=False)
|
69 |
+
|
70 |
+
if not fs.exists(EMAIL_PATH):
|
71 |
+
logger.info("Creating email file")
|
72 |
+
with fs.open(EMAIL_PATH, 'wb') as f:
|
73 |
+
existing_content = ''
|
74 |
+
new_content = existing_content
|
75 |
+
with fs.open(EMAIL_PATH, 'w') as f:
|
76 |
+
f.write(new_content.encode('utf-8'))
|
77 |
|
78 |
def write_email(email):
|
79 |
if fs.exists(EMAIL_PATH):
|
|
|
133 |
|
134 |
send_task(payload)
|
135 |
|
|
|
|
|
136 |
def decode_audio_array(base64_string):
|
137 |
bytes_data = base64.b64decode(base64_string)
|
138 |
|
|
|
148 |
response = requests.post(CREATE_TASK_URL,json=payload,headers=header)
|
149 |
try:
|
150 |
response = response.json()
|
151 |
+
except Exception as e:
|
152 |
+
logger.error("Error while sending task %s",e)
|
153 |
+
logger.debug("Payload which caused the error %s",payload)
|
154 |
return "error please try again"
|
155 |
|
156 |
if payload["task"] == "transcribe_with_fastapi":
|
|
|
197 |
return transcript
|
198 |
|
199 |
def transcribe_audio():
|
200 |
+
with st.spinner("🎯 Transcribing audio... this may take up to 30 seconds"):
|
201 |
+
models_list = ["Ori Apex", "Ori Apex XT", "deepgram", "Ori Swift", "Ori Prime","azure"]
|
202 |
+
model1_name, model2_name = random.sample(models_list, 2)
|
203 |
|
204 |
+
st.session_state.option_1_model_name = model1_name
|
205 |
+
st.session_state.option_2_model_name = model2_name
|
|
|
|
|
|
|
206 |
|
207 |
+
time_1 = time.time()
|
208 |
+
transcript1 = call_function(model1_name)
|
209 |
+
time_2 = time.time()
|
210 |
+
transcript2 = call_function(model2_name)
|
211 |
+
time_3 = time.time()
|
212 |
|
213 |
+
st.session_state.option_2_response_time = round(time_3 - time_2,3)
|
214 |
+
st.session_state.option_1_response_time = round(time_2 - time_1,3)
|
215 |
|
216 |
|
217 |
return transcript1, transcript2
|
|
|
466 |
st.markdown(f"<h3 style='margin-top: 0;'>{value}</h3>", unsafe_allow_html=True)
|
467 |
|
468 |
def on_refresh_click():
|
469 |
+
with st.spinner("Refreshing data... please wait"):
|
470 |
+
with fs.open(SAVE_PATH, 'rb') as f:
|
471 |
+
st.session_state.df = pd.read_csv(f)
|
472 |
|
473 |
+
try:
|
474 |
+
with fs.open(ELO_JSON_PATH,'r') as f:
|
475 |
+
st.session_state.elo_json = json.load(f)
|
476 |
+
except Exception as e:
|
477 |
+
logger.error("Error while reading elo json file %s",e)
|
478 |
+
st.session_state.elo_json = None
|
479 |
|
480 |
+
try:
|
481 |
+
with fs.open(ELO_CSV_PATH,'rb') as f:
|
482 |
+
st.session_state.elo_df = pd.read_csv(f)
|
483 |
+
except Exception as e:
|
484 |
+
logger.error("Error while reading elo csv file %s",e)
|
485 |
+
st.session_state.elo_df = None
|
486 |
|
487 |
def dashboard():
|
488 |
st.title('Model Arena Scoreboard')
|
|
|
491 |
with fs.open(SAVE_PATH, 'rb') as f:
|
492 |
st.session_state.df = pd.read_csv(f)
|
493 |
if "elo_json" not in st.session_state:
|
494 |
+
with fs.open(ELO_JSON_PATH,'r') as f:
|
495 |
+
elo_json = json.load(f)
|
496 |
+
st.session_state.elo_json = elo_json
|
|
|
|
|
497 |
if "elo_df" not in st.session_state:
|
498 |
+
with fs.open(ELO_CSV_PATH,'rb') as f:
|
499 |
+
elo_df = pd.read_csv(f)
|
500 |
+
st.session_state.elo_df = elo_df
|
|
|
|
|
501 |
|
502 |
st.button("Refresh",on_click=on_refresh_click)
|
503 |
|
|
|
563 |
appearance_chart = create_appearance_chart(metrics)
|
564 |
st.plotly_chart(appearance_chart, use_container_width=True)
|
565 |
|
566 |
+
if st.session_state.elo_json is not None and st.session_state.elo_df is not None:
|
567 |
st.header('Elo Ratings')
|
568 |
st.dataframe(pd.DataFrame(st.session_state.elo_json,index=[0]),use_container_width=True)
|
569 |
elo_progression_chart = create_elo_chart(st.session_state.elo_df)
|
|
|
750 |
st.button("Prefer None",on_click=on_option_none_click)
|
751 |
|
752 |
with scoreboard:
|
753 |
+
if st.session_state.logged_in or os.getenv("IS_TEST"):
|
754 |
dashboard()
|
755 |
else:
|
756 |
with st.form("contact_us_form"):
|
|
|
777 |
with about_tab:
|
778 |
about()
|
779 |
|
780 |
+
create_files()
|
781 |
main()
|
logger.py
ADDED
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import logging
|
2 |
+
import os
|
3 |
+
|
4 |
+
loglevel = os.getenv("LOGLEVEL", "INFO")
|
5 |
+
|
6 |
+
|
7 |
+
logger = logging.getLogger("App")
|
8 |
+
logger.setLevel(loglevel)
|
9 |
+
|
10 |
+
console_formatter = logging.Formatter("%(name)s: %(levelname)s -> [%(filename)s:%(lineno)s - %(funcName)s] %(message)s")
|
11 |
+
|
12 |
+
console_handler = logging.StreamHandler()
|
13 |
+
console_handler.setFormatter(console_formatter)
|
14 |
+
logger.addHandler(console_handler)
|