File size: 2,944 Bytes
fc10d08
 
 
 
 
 
 
 
cf2b99a
 
fc10d08
cf2b99a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
fc10d08
 
 
 
 
 
8c297cc
fc10d08
 
 
 
 
 
cf2b99a
 
 
 
 
 
 
 
fc10d08
 
 
 
 
 
 
 
 
 
 
 
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
70
71
72
73
74
75
76
import gradio as gr
from fastapi import FastAPI
from CriticalThinking.app.main import app as fastapi_app

# The FastAPI app is already initialized in CriticalThinking.app.main
# We can just mount it or use it as the main app.
# Here we will mount Gradio onto the existing FastAPI app.

import httpx

def analyze_interface(repo_url, project_description):
    if not repo_url and not project_description:
        return "Please provide at least a project description."
    
    try:
        # Call the local FastAPI endpoint
        with httpx.Client() as client:
            response = client.post(
                "http://localhost:7860/analyze",
                json={
                    "repo_url": repo_url if repo_url else None,
                    "project_description": project_description
                },
                timeout=10.0
            )
            response.raise_for_status()
            data = response.json()
            task_id = data.get("task_id")
            return f"Analysis started! Task ID: {task_id}\n\nYou can check the report at: /report/{task_id}"
    except Exception as e:
        return f"Error starting analysis: {str(e)}"

def get_report_interface(task_id):
    if not task_id:
        return "Please provide a Task ID."
    try:
        with httpx.Client() as client:
            response = client.get(f"http://localhost:7860/report/{task_id}")
            response.raise_for_status()
            return response.json()
    except Exception as e:
        return f"Error fetching report: {str(e)}"

with gr.Blocks(title="Critical Code Agent") as demo:
    gr.Markdown("# 🦀 Critical Code Agent")
    gr.Markdown("Autonomous agent system for deep architectural analysis and software weakness identification.")
    
    with gr.Row():
        repo_url = gr.Textbox(label="Repository URL (Optional)", placeholder="https://github.com/username/repo")
        project_desc = gr.Textbox(label="Project Description", placeholder="Brief description of the project")
    
    analyze_btn = gr.Button("Analyze Repository", variant="primary")
    output = gr.Textbox(label="Status")
    
    analyze_btn.click(analyze_interface, inputs=[repo_url, project_desc], outputs=output)

    gr.Markdown("### Check Report Status")
    with gr.Row():
        task_id_input = gr.Textbox(label="Task ID")
        report_btn = gr.Button("Get Report")
    
    report_output = gr.JSON(label="Analysis Report")
    report_btn.click(get_report_interface, inputs=[task_id_input], outputs=report_output)
    
    gr.Markdown("### API Endpoints")
    gr.Markdown("- `POST /analyze`: Submit a repository for analysis")
    gr.Markdown("- `GET /report/{task_id}`: Retrieve analysis report")
    gr.Markdown("- `GET /health`: Check service health")

# Mount Gradio to the FastAPI app
app = gr.mount_gradio_app(fastapi_app, demo, path="/")

if __name__ == "__main__":
    import uvicorn
    uvicorn.run(app, host="0.0.0.0", port=7860)