LegalSearchApp / app.py
Nikolay Banar
Add application file search deleted
d8255c3
# 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()