File size: 2,245 Bytes
8e0ebb3
 
 
d8255c3
8e0ebb3
 
 
d8255c3
8e0ebb3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d8255c3
 
 
 
 
 
 
 
 
 
8e0ebb3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# coding=utf-8
import streamlit as st
import json
# from search import TFIDF, GenClient


def display_search_results(results, page_number, results_per_page):
    pass
    st.title("Search Results")
    start_idx = (page_number - 1) * results_per_page
    end_idx = start_idx + results_per_page

    for i, result in enumerate(results[start_idx:end_idx]):
        if start_idx + i > 10:
            st.write(f"{start_idx + i + 1}. [link](https://www.vlaanderen.be{result['link']}):\n PDPPDP \n {result['text']}")
        else:
            st.write(f"{start_idx + i + 1}. [{result['Nummer']}](https://www.vlaanderen.be{result['link']}):")
            first_index = result['summary'].find('{')
            last_index = result['summary'].rfind('}')
            print(first_index, last_index)
            summary = result['summary'][first_index:last_index+1]
            print(summary)
            summary = json.loads(summary)
            print(summary)
            if summary['relevancy'] == 'YES':
                st.write(f"{summary['answer']}")

        # st.write(f"{result['text']}")
        relevant = st.checkbox(f"Is this document {start_idx + i} relevant?")


# Function to annotate documents
def main():
    st.title("Legal Search Engine")
    query = st.text_input("Enter your search query:")
    # model = TFIDF()
    # gen = GenClient()
    # if st.button("Search"):
    #     results = model.search_all([query], top_k=5)[0]
    #     for r in results:
    #         r['summary'] = gen.respond(query, r['text'])
    #
    #         # for
    #     #  gen.respond()
    #     st.session_state.results = results

    if "results" in st.session_state:
        results = st.session_state.results
        st.write("Search Results:")
        results_per_page = st.slider("Results per Page", min_value=1, max_value=len(results), value=5)
        page_number = st.number_input("Page Number", min_value=1, max_value=len(results), value=1)

        # Display search results for the selected page
        display_search_results(results, page_number, results_per_page)


# Press the green button in the gutter to run the script.
if __name__ == '__main__':
    # Sample data (replace with your own dataset)
    main()
    # display_all_documents()