Spaces:
Sleeping
Sleeping
| """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() | |