redrob / app.py
TASMAYU's picture
Update app.py
1af53e7 verified
Raw
History Blame Contribute Delete
1.72 kB
import gradio as gr
import subprocess
import os
def run_sample_trial():
# Sanity check to make sure the sample data exists
if not os.path.exists("candidates.jsonl"):
return "Error: Sample dataset 'candidates.jsonl' is missing from the container."
yield "Initializing Docker Container Sandbox Env...\nSpawning pipeline subprocess...\n\n"
# Trigger your actual optimized script file via terminal sub-process
# Trigger your actual optimized script file via terminal sub-process
process = subprocess.Popen(
[
"python", "run_pipeline.py",
"--candidates", "candidates.jsonl",
"--ranker", "regressor_no_prescore.pkl"
],
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
text=True
)
# Stream the console print blocks to the web text box line-by-line in real-time
output_log = ""
for line in process.stdout:
output_log += line
yield output_log
# Build the layout with a text output console block and a single Run button
with gr.Blocks(title="Redrob Ranker Sandbox") as demo:
gr.Markdown("# 🚀 Redrob Candidate Ranking Pipeline Sandbox")
gr.Markdown("Click the button below to execute the end-to-end processing pipeline on a sample data subset inside this container terminal.")
run_btn = gr.Button("▶ Run Pipeline Trial", variant="primary")
console_output = gr.Textbox(label="Terminal Live Output Logs", lines=22, max_lines=30, interactive=False)
run_btn.click(fn=run_sample_trial, outputs=console_output)
# Launch on port 7860 to clear the Hugging Face health checks
demo.queue().launch(server_name="0.0.0.0", server_port=7860)