parent
c6becadd82
commit
bb79b5b7bd
1 changed files with 85 additions and 21 deletions
@ -1,31 +1,95 @@ |
|||||||
import streamlit as st |
import streamlit as st |
||||||
#from identify_person import find_person |
from identify_person import find_person, verify |
||||||
# from _arango import arango |
from _arango import arango |
||||||
|
import re |
||||||
|
from time import time |
||||||
|
|
||||||
|
|
||||||
# db = arango.db |
@st.cache_data() |
||||||
# persons = list(db.collection('persons').all()) |
def get_persons(): |
||||||
|
return list(arango.db.collection('persons').all()) |
||||||
|
|
||||||
# q = 'for doc in persons filter doc.other == true return doc' |
@st.cache_data() |
||||||
# other_persons = [i for i in db.aql.execute(q)] |
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.cache_data() |
||||||
st.write('Start') |
def get_suggestions(person): |
||||||
# start_button = st.button('Start') |
print('Finding person', person) |
||||||
# if start_button: |
with st.spinner('Hämtar data...'): |
||||||
# st.write('Started') |
answers = find_person(person) |
||||||
# for person in other_persons: |
print('ANSWERS',answers) |
||||||
# answer = find_person(person) |
return answers |
||||||
# if not answer: |
|
||||||
# continue |
|
||||||
|
|
||||||
# for i in answer: |
db = arango.db |
||||||
# answer, person_in_arango, text = i |
|
||||||
|
|
||||||
# st.write(f"Answer: {answer}") |
if 'persons' not in st.session_state: |
||||||
# st.write(f"Person in Arango: {person_in_arango}") |
st.session_state.persons = get_persons() |
||||||
# st.write(f"Interrogation: {text}") |
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', '<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) |
||||||
Loading…
Reference in new issue