From 7b2b55324e78f90c95c9329c0d2fa016f15baed5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=B9i=20Nguy=E1=BB=85n=20T=E1=BA=A5n=20Sang?= Date: Tue, 13 Feb 2024 16:22:01 +0700 Subject: [PATCH] Added Add search language options: All, English, Vietnamese Add command support commands in ADPN --- adpn.py | 17 +++++++ log.txt | 2 - main.py | 113 ++++++++++++++++++++++++++++++++--------------- requirements.txt | 1 + 4 files changed, 96 insertions(+), 37 deletions(-) diff --git a/adpn.py b/adpn.py index 67fa8ec..f62e076 100644 --- a/adpn.py +++ b/adpn.py @@ -202,6 +202,23 @@ def change_reliability_by_user_id(user_id, new_reliability): if command == "exit": exit() + elif command == "help": + print(''' + exit: Exit ADPN. + help: This command. + clear: Clear the terminal. + start: Start the servers needed for MonoSearch. + api-config: Add the necessary API KEY environment variables to the servers. + atmt: Start ATMT STRT with keywords. + check: Lists the data that needs to be censored. + sync: Synchronize the censored database and the parent database (requirement: no data that needs to be censored). + sync-fts: Synchronize data in the root table with the virtual table. + log: Prints the server log. + users-list: Lists the list of users. + users-rel: Changes user reliability through their user id. + ''') + elif command == "clear": + subprocess.call("cls", shell=True) elif command == "start": if os.environ.get('SG_API_KEY') is None or os.environ.get('GSB_API_KEY') is None: print('The required API KEY to start the servers was not found, please use the "api-config" command to set the required environment API KEY variables.') diff --git a/log.txt b/log.txt index aaa4731..e69de29 100644 --- a/log.txt +++ b/log.txt @@ -1,2 +0,0 @@ -SYS: Loaded: users-account.db -SYS: Loaded: users-account.db diff --git a/main.py b/main.py index ea4d153..80083cf 100644 --- a/main.py +++ b/main.py @@ -1,5 +1,6 @@ import streamlit as st import time +from langdetect import detect from initializer.loader import database_loader from manager.manager import * from search.index import Search_Data @@ -34,8 +35,12 @@ with col1: keyword = st.text_input('Try to search something!', placeholder='Try to search something!', label_visibility='collapsed') + options_types = ['Text', 'Image', 'Video'] + search_type = st.radio('Type:', options_types, index=0) with col2: submitted1 = st.form_submit_button('Search') + options_language = ['all', 'en', 'vi'] + search_language = st.radio('Language:', options_language, index=0) with col3: submitted2 = st.form_submit_button('Add') with col4: @@ -43,9 +48,6 @@ with col5: submitted4 = st.form_submit_button('Remove') - options_types = ['Text', 'Image', 'Video'] - search_type = st.radio('', options_types, index=0) - if search_type == 'Text': conn = conn0 elif search_type == 'Image': @@ -105,43 +107,84 @@ if Search_Result is None: st.write("No results found") else: - for row in Search_Result: - row2 = return_special_characters(row[2]) - row6 = return_special_characters(row[6]) - row_title = row2.replace('\n', ' ') - row_title = row_title.replace(':', ' ') - row_shorttext = row6.replace('\n', ' ') - row_shorttext = row_shorttext.replace('```', ' ') - st.markdown("### [" + row_title + ']' + '(' + row[1] + ') ' + '```' + str(row[0]) + '```') - st.markdown(row_shorttext) - st.markdown("   ") + if search_language == 'all': + for row in Search_Result: + row2 = return_special_characters(row[2]) + row6 = return_special_characters(row[6]) + row_title = row2.replace('\n', ' ') + row_title = row_title.replace(':', ' ') + row_shorttext = row6.replace('\n', ' ') + row_shorttext = row_shorttext.replace('```', ' ') + st.markdown("### [" + row_title + ']' + '(' + row[1] + ') ' + '```' + str(row[0]) + '```') + st.markdown(row_shorttext) + st.markdown("   ") + else: + for row in Search_Result: + if detect(row[2]) == search_language or detect(row[6]) == search_language: + row2 = return_special_characters(row[2]) + row6 = return_special_characters(row[6]) + row_title = row2.replace('\n', ' ') + row_title = row_title.replace(':', ' ') + row_shorttext = row6.replace('\n', ' ') + row_shorttext = row_shorttext.replace('```', ' ') + st.markdown("### [" + row_title + ']' + '(' + row[1] + ') ' + '```' + str(row[0]) + '```') + st.markdown(row_shorttext) + st.markdown("   ") elif search_type == 'Image': if Search_Result is None: st.write("No results found") else: - for i in range(0, len(Search_Result), 2): - cols = st.columns(2) - for j in range(2): - if i + j < len(Search_Result): - row = Search_Result[i + j] - cols[j].image(image=row[1]) - row2 = return_special_characters(row[2]) - row_title = row2.replace('\n', ' ') - row_title = row_title.replace(':', ' ') - cols[j].markdown("### [" + row_title + ']' + '(' + row[1] + ')' + '```' + str(row[0]) + '```') - cols[j].markdown(row[4]) - cols[j].markdown("   ") + if search_language == 'all': + for i in range(0, len(Search_Result), 2): + cols = st.columns(2) + for j in range(2): + if i + j < len(Search_Result): + row = Search_Result[i + j] + cols[j].image(image=row[1]) + row2 = return_special_characters(row[2]) + row_title = row2.replace('\n', ' ') + row_title = row_title.replace(':', ' ') + cols[j].markdown("### [" + row_title + ']' + '(' + row[1] + ')' + '```' + str(row[0]) + '```') + cols[j].markdown(row[4]) + cols[j].markdown("   ") + else: + for i in range(0, len(Search_Result), 2): + if detect(row[2]) == search_language: + cols = st.columns(2) + for j in range(2): + if i + j < len(Search_Result): + row = Search_Result[i + j] + cols[j].image(image=row[1]) + row2 = return_special_characters(row[2]) + row_title = row2.replace('\n', ' ') + row_title = row_title.replace(':', ' ') + cols[j].markdown("### [" + row_title + ']' + '(' + row[1] + ')' + '```' + str(row[0]) + '```') + cols[j].markdown(row[4]) + cols[j].markdown("   ") elif search_type == 'Video': if Search_Result is None: st.write("No results found") else: - for row in Search_Result: - col1, col2 = st.columns([1, 3]) - col1.video(row[1]) - row2 = return_special_characters(row[2]) - row_title = row2.replace('\n', ' ') - row_title = row_title.replace(':', ' ') - col2.markdown('```' + str(row[0]) + '``` ```' + row[1] + '```') - col2.markdown("### [" + row_title + ']' + '(' + row[1] + ')') - col2.markdown(row[7]) - st.markdown("   ") + if search_language == 'all': + for row in Search_Result: + col1, col2 = st.columns([1, 3]) + col1.video(row[1]) + row2 = return_special_characters(row[2]) + row_title = row2.replace('\n', ' ') + row_title = row_title.replace(':', ' ') + col2.markdown('```' + str(row[0]) + '``` ```' + row[1] + '```') + col2.markdown("### [" + row_title + ']' + '(' + row[1] + ')') + col2.markdown(row[7]) + st.markdown("   ") + else: + for row in Search_Result: + if detect(row[2]) == search_language: + col1, col2 = st.columns([1, 3]) + col1.video(row[1]) + row2 = return_special_characters(row[2]) + row_title = row2.replace('\n', ' ') + row_title = row_title.replace(':', ' ') + col2.markdown('```' + str(row[0]) + '``` ```' + row[1] + '```') + col2.markdown("### [" + row_title + ']' + '(' + row[1] + ')') + col2.markdown(row[7]) + st.markdown("   ") diff --git a/requirements.txt b/requirements.txt index ceff335..a424663 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,4 @@ +langdetect streamlit sendgrid requests