DocIndexer / app.py
om4r932's picture
V2 (changed data storage method + rework)
22ee398
raw
history blame
1.84 kB
import subprocess
import warnings, os
warnings.filterwarnings("ignore")
os.environ["CURL_CA_BUNDLE"] = ""
from dotenv import load_dotenv
import gradio as gr
load_dotenv()
hf_token = os.environ["HF_TOKEN"]
SCRIPT_DOC = "tdoc_indexer.py"
SCRIPT_SPEC = "spec_indexer.py"
SCRIPT_BM25 = "bm25_maker.py"
def get_script_output(script_path, current_log=""):
accumulated_output = current_log
process = subprocess.Popen(
["python", script_path],
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
bufsize=1,
universal_newlines=True
)
for line in process.stdout:
accumulated_output += line
yield accumulated_output
process.stdout.close()
process.wait()
yield accumulated_output
def index_tdocs():
log_output = "⏳ Indexation en cours...\n"
for log in get_script_output(SCRIPT_DOC):
yield log
log_output = log
log_output += "✅ Terminé.\n"
yield log_output
def index_specifications():
log_output = "⏳ Indexation en cours...\n"
for log in get_script_output(SCRIPT_SPEC):
yield log
log_output = log
for log in get_script_output(SCRIPT_BM25):
yield log
log_output = log
log_output += "✅ Terminé.\n"
yield log_output
with gr.Blocks(theme=gr.themes.Soft()) as demo:
gr.Markdown("# 📄 3GPP Indexer Main Menu")
with gr.Row() as r1:
with gr.Column():
tdocs_btn = gr.Button("Re-index TDocs", variant="primary")
with gr.Column():
spec_btn = gr.Button("Re-index Specifications", variant="primary")
out = gr.Textbox(label="Output", lines=25, autoscroll=True, interactive=False)
tdocs_btn.click(index_tdocs, outputs=[out])
spec_btn.click(index_specifications, outputs=[out])
demo.queue().launch()