Team Ai
Apppublic

AUXteam/Critical_Code_Agent

sourceHugging Faceupdated 8mo agoView on Hugging Face
0likes
hf_app.py76 linesDownload Raw Back to root
1import gradio as gr2from fastapi import FastAPI3from CriticalThinking.app.main import app as fastapi_app4 5# The FastAPI app is already initialized in CriticalThinking.app.main6# We can just mount it or use it as the main app.7# Here we will mount Gradio onto the existing FastAPI app.8 9import httpx10 11def analyze_interface(repo_url, project_description):12    if not repo_url and not project_description:13        return "Please provide at least a project description."14    15    try:16        # Call the local FastAPI endpoint17        with httpx.Client() as client:18            response = client.post(19                "http://localhost:7860/analyze",20                json={21                    "repo_url": repo_url if repo_url else None,22                    "project_description": project_description23                },24                timeout=10.025            )26            response.raise_for_status()27            data = response.json()28            task_id = data.get("task_id")29            return f"Analysis started! Task ID: {task_id}\n\nYou can check the report at: /report/{task_id}"30    except Exception as e:31        return f"Error starting analysis: {str(e)}"32 33def get_report_interface(task_id):34    if not task_id:35        return "Please provide a Task ID."36    try:37        with httpx.Client() as client:38            response = client.get(f"http://localhost:7860/report/{task_id}")39            response.raise_for_status()40            return response.json()41    except Exception as e:42        return f"Error fetching report: {str(e)}"43 44with gr.Blocks(title="Critical Code Agent") as demo:45    gr.Markdown("# 🦀 Critical Code Agent")46    gr.Markdown("Autonomous agent system for deep architectural analysis and software weakness identification.")47    48    with gr.Row():49        repo_url = gr.Textbox(label="Repository URL (Optional)", placeholder="https://github.com/username/repo")50        project_desc = gr.Textbox(label="Project Description", placeholder="Brief description of the project")51    52    analyze_btn = gr.Button("Analyze Repository", variant="primary")53    output = gr.Textbox(label="Status")54    55    analyze_btn.click(analyze_interface, inputs=[repo_url, project_desc], outputs=output)56 57    gr.Markdown("### Check Report Status")58    with gr.Row():59        task_id_input = gr.Textbox(label="Task ID")60        report_btn = gr.Button("Get Report")61    62    report_output = gr.JSON(label="Analysis Report")63    report_btn.click(get_report_interface, inputs=[task_id_input], outputs=report_output)64    65    gr.Markdown("### API Endpoints")66    gr.Markdown("- `POST /analyze`: Submit a repository for analysis")67    gr.Markdown("- `GET /report/{task_id}`: Retrieve analysis report")68    gr.Markdown("- `GET /health`: Check service health")69 70# Mount Gradio to the FastAPI app71app = gr.mount_gradio_app(fastapi_app, demo, path="/")72 73if __name__ == "__main__":74    import uvicorn75    uvicorn.run(app, host="0.0.0.0", port=7860)76