Spaces:
Sleeping
Sleeping
File size: 3,032 Bytes
ca2b985 | 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 63 64 65 66 67 68 69 | """Gradio application layout and launch."""
import logging
from pathlib import Path
import gradio as gr
from code_tribunal.config import TribunalConfig
from code_tribunal.ui.exports import export_md, export_pdf
from code_tribunal.ui.pipeline import handle_question, run_courtroom
from code_tribunal.ui.styles import CSS
logging.basicConfig(level=logging.DEBUG, format="[%(asctime)s][%(levelname)s] %(message)s", datefmt="%H:%M:%S")
logging.getLogger("crewai").setLevel(logging.WARNING)
def create_app() -> gr.Blocks:
logo = Path(__file__).resolve().parent.parent.parent.parent / "assets" / "logo.png"
with gr.Blocks(title="CodeTribunal") as app:
with gr.Column(visible=True) as hero:
if logo.exists():
gr.Image(value=str(logo), show_label=False, height=160, container=False, elem_classes=["hero-logo"])
gr.Markdown("# CodeTribunal\n### The AI Courtroom That Exposes Bad Freelance Code", elem_classes=["hero-title"])
gr.Markdown("Upload a .zip of code and watch a multi-agent forensic investigation unfold.", elem_classes=["hero-subtitle"])
with gr.Column(visible=True, elem_classes=["upload-area"]) as upload:
code_input = gr.File(label="Drop your .zip here", file_types=[".zip"], interactive=True)
with gr.Column(visible=False) as processing:
status = gr.Markdown("Initializing...", elem_classes=["status-phase"])
chatbot = gr.Chatbot(label="Courtroom Transcript", height=600, elem_classes=["chatbot"])
with gr.Row():
exp_md = gr.Button("📄 Export Markdown", visible=False)
exp_pdf = gr.Button("📑 Export PDF", visible=False)
exp_file = gr.File(label="Download", visible=False)
qa_input = gr.Textbox(label="Ask a follow-up", placeholder="e.g., 'Why was eval() critical?'", visible=False)
qa_btn = gr.Button("🕵️ Ask Expert Witness", variant="primary", visible=False)
state = gr.State(value={})
code_input.upload(
fn=run_courtroom, inputs=[code_input],
outputs=[hero, upload, processing, status, chatbot, exp_md, exp_pdf, exp_file, state],
).then(
fn=lambda: (gr.update(visible=True), gr.update(visible=True)),
outputs=[qa_input, qa_btn],
)
exp_md.click(fn=export_md, inputs=[state], outputs=[exp_file])
exp_pdf.click(fn=export_pdf, inputs=[state], outputs=[exp_file])
qa_btn.click(fn=handle_question, inputs=[qa_input, chatbot, state], outputs=[chatbot, qa_input])
qa_input.submit(fn=handle_question, inputs=[qa_input, chatbot, state], outputs=[chatbot, qa_input])
return app
def main() -> None:
app = create_app()
app.launch(
server_name=TribunalConfig().server_host,
server_port=TribunalConfig().server_port,
css=CSS,
theme=gr.themes.Base(primary_hue="amber", secondary_hue="slate", neutral_hue="slate"),
)
if __name__ == "__main__":
main()
|