Spaces:
Build error
Build error
Update main.py
Browse files
main.py
CHANGED
|
@@ -10,7 +10,6 @@ import os
|
|
| 10 |
from pathlib import Path
|
| 11 |
from fastapi.middleware.cors import CORSMiddleware
|
| 12 |
|
| 13 |
-
# Initialize FastAPI app (critical to name it 'app')
|
| 14 |
app = FastAPI(title="Code Evaluation & Optimization API")
|
| 15 |
|
| 16 |
# Required CORS configuration
|
|
@@ -35,12 +34,11 @@ try:
|
|
| 35 |
tokenizer = AutoTokenizer.from_pretrained(
|
| 36 |
MODEL_NAME,
|
| 37 |
cache_dir=str(CACHE_DIR)
|
| 38 |
-
)
|
| 39 |
model = AutoModelForCausalLM.from_pretrained(
|
| 40 |
MODEL_NAME,
|
| 41 |
device_map="auto",
|
| 42 |
torch_dtype=torch.float16,
|
| 43 |
-
cache_dir=str(CACHE_DIR)
|
| 44 |
except Exception as e:
|
| 45 |
raise RuntimeError(f"Failed to load model: {str(e)}")
|
| 46 |
|
|
@@ -78,7 +76,6 @@ def evaluate_code(user_code: str, lang: str) -> dict:
|
|
| 78 |
error_message = None if correctness else result.stderr.strip()
|
| 79 |
else:
|
| 80 |
return {"status": "error", "message": "Unsupported language", "score": 0}
|
| 81 |
-
|
| 82 |
except Exception as e:
|
| 83 |
return {"status": "error", "message": str(e), "score": 0}
|
| 84 |
|
|
|
|
| 10 |
from pathlib import Path
|
| 11 |
from fastapi.middleware.cors import CORSMiddleware
|
| 12 |
|
|
|
|
| 13 |
app = FastAPI(title="Code Evaluation & Optimization API")
|
| 14 |
|
| 15 |
# Required CORS configuration
|
|
|
|
| 34 |
tokenizer = AutoTokenizer.from_pretrained(
|
| 35 |
MODEL_NAME,
|
| 36 |
cache_dir=str(CACHE_DIR)
|
|
|
|
| 37 |
model = AutoModelForCausalLM.from_pretrained(
|
| 38 |
MODEL_NAME,
|
| 39 |
device_map="auto",
|
| 40 |
torch_dtype=torch.float16,
|
| 41 |
+
cache_dir=str(CACHE_DIR))
|
| 42 |
except Exception as e:
|
| 43 |
raise RuntimeError(f"Failed to load model: {str(e)}")
|
| 44 |
|
|
|
|
| 76 |
error_message = None if correctness else result.stderr.strip()
|
| 77 |
else:
|
| 78 |
return {"status": "error", "message": "Unsupported language", "score": 0}
|
|
|
|
| 79 |
except Exception as e:
|
| 80 |
return {"status": "error", "message": str(e), "score": 0}
|
| 81 |
|