You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
95 lines
3.1 KiB
95 lines
3.1 KiB
import streamlit as st |
|
from identify_person import find_person, verify |
|
from _arango import arango |
|
import re |
|
from time import time |
|
|
|
|
|
@st.cache_data() |
|
def get_persons(): |
|
return list(arango.db.collection('persons').all()) |
|
|
|
@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)] |
|
|
|
@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 |
|
|
|
db = arango.db |
|
|
|
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() |
|
|
|
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', '<br>') |
|
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) |