diff --git a/check_names_app.py b/check_names_app.py index 895c29b..6af9775 100644 --- a/check_names_app.py +++ b/check_names_app.py @@ -1,31 +1,95 @@ import streamlit as st -#from identify_person import find_person -# from _arango import arango +from identify_person import find_person, verify +from _arango import arango +import re +from time import time -# db = arango.db -# persons = list(db.collection('persons').all()) +@st.cache_data() +def get_persons(): + return list(arango.db.collection('persons').all()) -# q = 'for doc in persons filter doc.other == true return doc' -# other_persons = [i for i in db.aql.execute(q)] +@st.cache_data() +def get_other_persons(): + q = 'for doc in persons filter doc.other == true return doc' + return [i for i in db.aql.execute(q)] -print('Start') -st.write('Start') -# start_button = st.button('Start') -# if start_button: -# st.write('Started') -# for person in other_persons: -# answer = find_person(person) -# if not answer: -# continue +@st.cache_data() +def get_suggestions(person): + print('Finding person', person) + with st.spinner('Hämtar data...'): + answers = find_person(person) + print('ANSWERS',answers) + return answers -# for i in answer: -# answer, person_in_arango, text = i +db = arango.db -# st.write(f"Answer: {answer}") -# st.write(f"Person in Arango: {person_in_arango}") -# st.write(f"Interrogation: {text}") +if 'persons' not in st.session_state: + st.session_state.persons = get_persons() + st.session_state.persons_names = [i['name'] for i in st.session_state.persons] + st.session_state.persons_dict = {i['name']: i['_key'] for i in st.session_state.persons} +if 'other_persons' not in st.session_state: + st.session_state.other_persons = get_other_persons() -# st.stop() +if 'radio1' in st.session_state: + del st.session_state['radio1'] +if 'suggestions' not in st.session_state: + st.session_state.suggestions = [] +# If suggestions are all used up + + +if st.session_state.suggestions == []: + st.session_state.other_person = st.session_state.other_persons.pop(0) + suggestions = get_suggestions(st.session_state.other_person) + print(suggestions) + if suggestions == None: + st.rerun() + else: + st.session_state.suggestions = suggestions + +st.session_state.suggestion = st.session_state.suggestions.pop(0) + +answer, person_in_arango, interrogation_doc, other_person, found_person, found_person_info, person = st.session_state.suggestion + +text = interrogation_doc['text'] +answer = answer.replace('\n', ' ') +st.markdown(f'Är :blue[{other_person}] samma som :blue[{found_person}]?') +st.write(f'(från förhör med {interrogation_doc["person"]})') +if 'JA' in answer: + st.markdown(f'🤖\n:green[{answer}]') + radio_index = 0 +elif 'NEJ' in answer: + radio_index = 1 + st.markdown(f'🤖\n:red[{answer}]') +else: + radio_index = None + st.markdown(f'🤖\n{answer}') + +with st.form('Form'): + with st.expander('Mer information'): + text = re.sub(r'\n\n+', '\n', text) + text = text.replace('\n', '
') + st.markdown(f'##### Förhöret:\n{text}', unsafe_allow_html=True) + + st.markdown(f'##### {found_person}:') + st.markdown(found_person_info, unsafe_allow_html=True) + + user_choice = st.radio('', ('Ja', 'Nej', 'Vet ej'), key=time(), index=radio_index) + other_choice = st.selectbox('Välj alla som stämmer', st.session_state.persons_names, placeholder='Sök en annan', index=None, key=time() + 'multiselect') + + st.form_submit_button('Nästa') + +if other_choice: + person_in_arango = db.collection('persons').get(st.session_state.persons_dict[other_choice]) + print('Yes', person, person_in_arango, text, db) + #verify('Yes', person, person_in_arango, text, db) +elif user_choice == 'Ja': + print(('Yes', person, person_in_arango)) + #verify('Yes', person, person_in_arango, text, db) +elif user_choice == 'Nej': + pass +elif user_choice == 'Vet ej': + pass + #verify('Unknown', person, person_in_arango, text, db) \ No newline at end of file