TusharsinghBaghel commited on
Commit
f083f90
·
verified ·
1 Parent(s): 77c0061

Upload 4 files

Browse files
Files changed (4) hide show
  1. Dockerfile +16 -0
  2. README.md +73 -12
  3. app.py +151 -0
  4. requirements.txt +5 -0
Dockerfile ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM python:3.11-slim
2
+
3
+ WORKDIR /app
4
+
5
+ # Copy requirements and install dependencies
6
+ COPY requirements.txt .
7
+ RUN pip install --no-cache-dir -r requirements.txt
8
+
9
+ # Copy application code
10
+ COPY app.py .
11
+
12
+ # Expose port 7860 (HuggingFace Spaces standard)
13
+ EXPOSE 7860
14
+
15
+ # Run the application
16
+ CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
README.md CHANGED
@@ -1,12 +1,73 @@
1
- ---
2
- title: Synhack
3
- emoji: 👀
4
- colorFrom: pink
5
- colorTo: pink
6
- sdk: gradio
7
- sdk_version: 5.49.1
8
- app_file: app.py
9
- pinned: false
10
- ---
11
-
12
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: Architecture Evaluator LLM
3
+ emoji: 🏗️
4
+ colorFrom: blue
5
+ colorTo: green
6
+ sdk: docker
7
+ pinned: false
8
+ ---
9
+
10
+ # Architecture Evaluator LLM
11
+
12
+ An AI-powered system design architecture evaluator using **Groq's FREE ultra-fast inference** with advanced reasoning models.
13
+
14
+ ## Features
15
+
16
+ - 🚀 **FREE** - Uses Groq's free API (no costs!)
17
+ - ⚡ **FAST** - Groq provides blazing-fast inference
18
+ - 🧠 **Smart** - DeepSeek R1 reasoning model for deep analysis
19
+ - Evaluates system design architectures based on multiple heuristics
20
+ - Provides detailed suggestions and recommendations
21
+ - Returns structured JSON responses
22
+ - Easy to integrate with any frontend
23
+
24
+ ## API Endpoints
25
+
26
+ ### POST /evaluate
27
+ Evaluates a system architecture.
28
+
29
+ **Request Body:**
30
+ ```json
31
+ {
32
+ "question": "Your question or context about the architecture",
33
+ "architecture": {
34
+ // Your architecture JSON with components and links
35
+ }
36
+ }
37
+ ```
38
+
39
+ **Response:**
40
+ ```json
41
+ {
42
+ "heuristic_scores": {
43
+ "DURABILITY": 8.5,
44
+ "AVAILABILITY": 9.0,
45
+ "ENERGY_EFFICIENCY": 7.5,
46
+ "CONSISTENCY": 8.0,
47
+ "MAINTAINABILITY": 7.0,
48
+ "LATENCY": 8.5,
49
+ "COST": 6.5,
50
+ "SECURITY": 8.0,
51
+ "THROUGHPUT": 8.5,
52
+ "SCALABILITY": 9.0
53
+ },
54
+ "suggestion": "Your architecture shows strong scalability..."
55
+ }
56
+ ```
57
+
58
+ ## Environment Variables
59
+
60
+ - `GROQ_API_KEY`: Your Groq API key (required - get free at https://console.groq.com)
61
+ - `MODEL_NAME`: Model to use (default: deepseek-r1-distill-llama-70b)
62
+ - Available models:
63
+ - `deepseek-r1-distill-llama-70b` - Best reasoning (default)
64
+ - `llama-3.3-70b-versatile` - Great all-rounder
65
+ - `llama-3.1-70b-versatile` - Fast and capable
66
+
67
+ ## Getting Your Free Groq API Key
68
+
69
+ 1. Go to https://console.groq.com
70
+ 2. Sign up for a free account
71
+ 3. Navigate to API Keys section
72
+ 4. Create a new API key
73
+ 5. Copy and use it (completely FREE!)
app.py ADDED
@@ -0,0 +1,151 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import FastAPI, HTTPException
2
+ from fastapi.middleware.cors import CORSMiddleware
3
+ from pydantic import BaseModel
4
+ from typing import Dict, List, Any, Optional
5
+ import os
6
+ from groq import Groq
7
+
8
+ app = FastAPI(title="Architecture Evaluator LLM")
9
+
10
+ # Enable CORS for all origins (adjust in production)
11
+ app.add_middleware(
12
+ CORSMiddleware,
13
+ allow_origins=["*"],
14
+ allow_credentials=True,
15
+ allow_methods=["*"],
16
+ allow_headers=["*"],
17
+ )
18
+
19
+ # Initialize Groq client - FREE and FAST!
20
+ client = Groq(
21
+ api_key=os.getenv("GROQ_API_KEY", "your-groq-api-key-here")
22
+ )
23
+
24
+ class EvaluationRequest(BaseModel):
25
+ question: str
26
+ architecture: Dict[str, Any]
27
+
28
+ class HeuristicScores(BaseModel):
29
+ DURABILITY: float
30
+ AVAILABILITY: float
31
+ ENERGY_EFFICIENCY: float
32
+ CONSISTENCY: float
33
+ MAINTAINABILITY: float
34
+ LATENCY: float
35
+ COST: float
36
+ SECURITY: float
37
+ THROUGHPUT: float
38
+ SCALABILITY: float
39
+
40
+ class EvaluationResponse(BaseModel):
41
+ heuristic_scores: HeuristicScores
42
+ suggestion: str
43
+
44
+ def create_evaluation_prompt(question: str, architecture: Dict[str, Any]) -> str:
45
+ """Create a detailed prompt for the LLM to evaluate the architecture."""
46
+
47
+ prompt = f"""You are an expert system architect. Analyze the following system design architecture and provide an evaluation.
48
+
49
+ **Question/Context:**
50
+ {question}
51
+
52
+ **Architecture JSON:**
53
+ {architecture}
54
+
55
+ **Your Task:**
56
+ 1. Analyze the overall architecture based on the components and their connections (links)
57
+ 2. Calculate aggregate heuristic scores (0-10 scale) for the entire architecture considering:
58
+ - Individual component scores
59
+ - How components interact through links
60
+ - Overall system design patterns
61
+ - Redundancy and fault tolerance
62
+ - Data flow efficiency
63
+
64
+ 3. Provide constructive suggestions on:
65
+ - What's good about this architecture
66
+ - What could be improved
67
+ - Specific recommendations
68
+ - Alternative approaches if applicable
69
+
70
+ **Important:** You must respond with ONLY a valid JSON object in this exact format:
71
+ {{
72
+ "heuristic_scores": {{
73
+ "DURABILITY": <float between 0-10>,
74
+ "AVAILABILITY": <float between 0-10>,
75
+ "ENERGY_EFFICIENCY": <float between 0-10>,
76
+ "CONSISTENCY": <float between 0-10>,
77
+ "MAINTAINABILITY": <float between 0-10>,
78
+ "LATENCY": <float between 0-10>,
79
+ "COST": <float between 0-10>,
80
+ "SECURITY": <float between 0-10>,
81
+ "THROUGHPUT": <float between 0-10>,
82
+ "SCALABILITY": <float between 0-10>
83
+ }},
84
+ "suggestion": "<your detailed analysis and suggestions as a string>"
85
+ }}
86
+
87
+ Do not include any text outside the JSON object. Ensure all scores are numeric values between 0 and 10."""
88
+
89
+ return prompt
90
+
91
+ @app.get("/")
92
+ async def root():
93
+ return {
94
+ "message": "Architecture Evaluator LLM API",
95
+ "status": "online",
96
+ "endpoints": {
97
+ "/evaluate": "POST - Evaluate a system architecture",
98
+ "/health": "GET - Health check"
99
+ }
100
+ }
101
+
102
+ @app.get("/health")
103
+ async def health():
104
+ return {"status": "healthy"}
105
+
106
+ @app.post("/evaluate", response_model=EvaluationResponse)
107
+ async def evaluate_architecture(request: EvaluationRequest):
108
+ """
109
+ Evaluate a system design architecture using LLM.
110
+
111
+ Args:
112
+ request: Contains the question and architecture JSON
113
+
114
+ Returns:
115
+ EvaluationResponse with heuristic scores and suggestions
116
+ """
117
+ try:
118
+ # Create the prompt
119
+ prompt = create_evaluation_prompt(request.question, request.architecture)
120
+
121
+ # Call Groq LLM - Using best reasoning model (deepseek-r1-distill-llama-70b)
122
+ # Alternative models: llama-3.3-70b-versatile, llama-3.1-70b-versatile
123
+ response = client.chat.completions.create(
124
+ model=os.getenv("MODEL_NAME", "llama-3.3-70b-versatile"),
125
+ messages=[
126
+ {
127
+ "role": "system",
128
+ "content": "You are an expert system architect who provides detailed analysis and returns responses in strict JSON format."
129
+ },
130
+ {
131
+ "role": "user",
132
+ "content": prompt
133
+ }
134
+ ],
135
+ temperature=0.7,
136
+ response_format={"type": "json_object"} # Enforce JSON response
137
+ )
138
+
139
+ # Parse the response
140
+ import json
141
+ result = json.loads(response.choices[0].message.content)
142
+
143
+ # Validate and return
144
+ return EvaluationResponse(**result)
145
+
146
+ except Exception as e:
147
+ raise HTTPException(status_code=500, detail=f"Error evaluating architecture: {str(e)}")
148
+
149
+ if __name__ == "__main__":
150
+ import uvicorn
151
+ uvicorn.run(app, host="0.0.0.0", port=7860) # Port 7860 is standard for HuggingFace Spaces
requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ fastapi==0.115.0
2
+ uvicorn[standard]==0.32.0
3
+ pydantic==2.9.2
4
+ groq==0.11.0
5
+ python-multipart==0.0.12