Spaces:
Sleeping
Sleeping
ajaxwin commited on
Commit Β·
45bd962
1
Parent(s): 17ed3a7
fix: Update file paths and ensure model loading in PropertyRetriever
Browse filesFiles changed (5)
296 unmodified lines297298299300301302303296 unmodified lines```bashpip install -r requirements.txtuvicorn api.app:app --host 0.0.0.0 --port 7860 --reload```### Validate OpenEnv Compliance296 unmodified lines297298299300301302303296 unmodified lines```bashpip install -r requirements.txtuvicorn server.app:app --host 0.0.0.0 --port 7860 --reload```### Validate OpenEnv Compliance
16 unmodified lines1718192021222393 unmodified lines11711811912012112212312416 unmodified lines"""from typing import Dict, Optional, Unionfrom zipfile import Pathfrom fastapi import FastAPI, HTTPException, Query, Requestfrom fastapi.responses import FileResponse, JSONResponse93 unmodified lines- API clients (Accept: */*) β JSON summary"""accept = request.headers.get("accept", "")if "text/html" in accept and Path("./index.html").is_file():return FileResponse("./index.html", media_type="text/html", status_code=200)return JSONResponse(content=_ROOT_JSON, status_code=200)@app.get("/health")16 unmodified lines1718192021222393 unmodified lines11711811912012112212312416 unmodified lines"""from typing import Dict, Optional, Unionfrom pathlib import Pathfrom fastapi import FastAPI, HTTPException, Query, Requestfrom fastapi.responses import FileResponse, JSONResponse93 unmodified lines- API clients (Accept: */*) β JSON summary"""accept = request.headers.get("accept", "")if "text/html" in accept and Path("server/index.html").is_file():return FileResponse("server/index.html", media_type="text/html", status_code=200)return JSONResponse(content=_ROOT_JSON, status_code=200)@app.get("/health")
1234567891 unmodified line111213141516688 unmodified lines705706707708# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ# Landing page HTML# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββLANDING_HTML = """<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8" />1 unmodified line<title>SC Audit RL Environment</title><link rel="preconnect" href="https://fonts.googleapis.com" /><link href="https://fonts.googleapis.com/css2?family=Space+Mono:wght@400;700&family=DM+Sans:wght@300;400;500&display=swap" rel="stylesheet" /><style>*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }688 unmodified lines}</script></body></html>"""12341 unmodified line6789101112688 unmodified lines701702703704<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8" />1 unmodified line<title>SC Audit RL Environment</title><link rel="preconnect" href="https://fonts.googleapis.com" /><link href="https://fonts.googleapis.com/css2?family=Space+Mono:wght@400;700&family=DM+Sans:wght@300;400;500&display=swap" rel="stylesheet" /><link rel="icon" type="image/svg+xml" href="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M12 2L4.5 5.5V10.5C4.5 15.14 7.7 19.46 12 20.5C16.3 19.46 19.5 15.14 19.5 10.5V5.5L12 2Z' fill='none' stroke='%2300ff88' stroke-width='2'/%3E%3Crect x='10.5' y='9.5' width='3' height='3' rx='0.5' fill='%2300ff88'/%3E%3C/svg%3E"><style>*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }688 unmodified lines}</script></body></html>
92 unmodified lines9394959697989992 unmodified lines"""Handle GET_SIMILAR_RULE action."""if ctx._is_repeated(qkey):return "Repeated query.", Reward(value=-0.40, reason="Repeated query")similar_rule = PropertyRetrieverInstance.get_similar_property(ctx._target_fn["code"])if similar_rule is None:return (92 unmodified lines9394959697989910092 unmodified lines"""Handle GET_SIMILAR_RULE action."""if ctx._is_repeated(qkey):return "Repeated query.", Reward(value=-0.40, reason="Repeated query")PropertyRetrieverInstance.load_model() # Ensure model is loaded before queryingsimilar_rule = PropertyRetrieverInstance.get_similar_property(ctx._target_fn["code"])if similar_rule is None:return (
7 unmodified lines891011121314151613 unmodified lines3031323334353637388 unmodified lines4748495051525354554 unmodified lines606162636465667 unmodified linesimport pandas as pdimport numpy as npfrom sentence_transformers import SentenceTransformerfrom sklearn.preprocessing import normalizefrom data.data_loader import DEFAULT_CSV_PATHSIMILARITY_THRESHOLD = 0.8 # Adjust as needed based on validation13 unmodified lines"""self.df = pd.read_csv(DEFAULT_CSV_PATH)self.threshold = SIMILARITY_THRESHOLD# Use a lightweight, openβsource embedding modelself.embedder = SentenceTransformer('all-MiniLM-L6-v2')# Extract "critical code" from each property (use FunctionBodies)# Fallback to RelatedFunctions or RuleContent if FunctionBodies is missing8 unmodified linesself.critical_codes.append(str(code))# Compute embeddings for all critical codesself.embeddings = self.embedder.encode(self.critical_codes, show_progress_bar=True)# Normalize for dot product = cosine similarityself.embeddings = normalize(self.embeddings, norm='l2')def get_similar_property(self, input_code: str) -> str:"""4 unmodified linesreturn ""# Step β‘: Embed the subject codequery_emb = self.embedder.encode([input_code])query_emb = normalize(query_emb, norm='l2')# Step β’: Compute dot products with all database vectors7 unmodified lines891011121314151613 unmodified lines30313233343536373839404142434445468 unmodified lines555657585960616263644 unmodified lines697071727374757 unmodified linesimport pandas as pdimport numpy as npfrom sklearn.preprocessing import normalizefrom data.data_loader import DEFAULT_CSV_PATHfrom dotenv import dotenv_valuesSIMILARITY_THRESHOLD = 0.8 # Adjust as needed based on validation13 unmodified lines"""self.df = pd.read_csv(DEFAULT_CSV_PATH)self.threshold = SIMILARITY_THRESHOLDself.embedder = Nonedef load_model(self):"""Use a lightweight, openβsource embedding model."""if self.embedder is not None:from sentence_transformers import SentenceTransformerself.embedder = SentenceTransformer('all-MiniLM-L6-v2',use_auth_token=dotenv_values(".env").get('HF_TOKEN', ''))# Extract "critical code" from each property (use FunctionBodies)# Fallback to RelatedFunctions or RuleContent if FunctionBodies is missing8 unmodified linesself.critical_codes.append(str(code))# Compute embeddings for all critical codesself.embeddings = self.embedder.encode(self.critical_codes, show_progress_bar=True) #type: ignore# Normalize for dot product = cosine similarityself.embeddings = normalize(self.embeddings, norm='l2')def get_similar_property(self, input_code: str) -> str:"""4 unmodified linesreturn ""# Step β‘: Embed the subject codequery_emb = self.embedder.encode([input_code]) #type: ignorequery_emb = normalize(query_emb, norm='l2')# Step β’: Compute dot products with all database vectors
README.md+1-1
server/app.py+3-3
server/index.html+3-7
server/tasks/task2/actions.py+2-1
utils/propertyretriever.py+14-5