Spaces:
Sleeping
Sleeping
File size: 2,533 Bytes
701866f |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
from typing import Dict
import hmac
import streamlit as st
def process_olivia_data(transcription: dict) -> str:
phrases = transcription['phrases']
conversation = ''
for phrase in phrases:
conversation += 'Agent: ' if phrase['channel'] == 0 else 'Customer: '
parsed_phrase = ''.join(word['text'] for word in phrase['words'])
conversation += parsed_phrase
conversation += '\n\n\n'
return {'text': conversation}
def process_tethr_data(data: Dict) -> Dict:
extracted_words = []
participants = data.get("participants", [])
for participant in participants:
participant_type = 'Agent' if 'Agent' in participant.get("refType", "") else 'Customer'
utterances = participant.get("utterances", [])
for utterance in utterances:
words = utterance.get("words") # by words, not utterances since messed up
for word in words:
word_obj = {
'participant': participant_type,
'word': word.get('content', ''),
'start': word.get('startMs', None),
'end': word.get('endMs', None)
}
extracted_words.append(word_obj)
extracted_words.sort(key=lambda x: x['start']) # Sort by start time
conversation = ''
participant = None
for word in extracted_words:
if word['participant'] != participant:
if participant:
conversation += '\n\n'
participant = word['participant']
conversation += f'{participant}: '
conversation += f"{word['word']} "
return {'id': data['callId'], 'text': conversation}
def check_password():
"""Returns `True` if the user had the correct password."""
def password_entered():
"""Checks whether a password entered by the user is correct."""
if hmac.compare_digest(st.session_state["password"], st.secrets["PASSWORD"]):
st.session_state["password_correct"] = True
del st.session_state["password"] # Don't store the password.
else:
st.session_state["password_correct"] = False
# Return True if the passward is validated.
if st.session_state.get("password_correct", False):
return True
# Show input for password.
st.text_input(
"Password", type="password", on_change=password_entered, key="password"
)
if "password_correct" in st.session_state:
st.error("Incorrect password")
return False
|