Spaces:
Sleeping
Sleeping
Sgridda commited on
Commit ·
e4936f3
1
Parent(s): b64e7a0
env varaible
Browse files
main.py
CHANGED
|
@@ -6,6 +6,7 @@ import re
|
|
| 6 |
import json
|
| 7 |
from fastapi.responses import HTMLResponse
|
| 8 |
import requests
|
|
|
|
| 9 |
|
| 10 |
|
| 11 |
# ----------------------------
|
|
@@ -15,8 +16,12 @@ import requests
|
|
| 15 |
MODEL_NAME = "Salesforce/codegen-350M-mono"
|
| 16 |
DEVICE = "cuda" if torch.cuda.is_available() else "cpu"
|
| 17 |
|
| 18 |
-
#
|
| 19 |
-
HF_API_KEY = "
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
HF_MODEL_NAME = "bigcode/starcoder" # Replace with the best model for code review
|
| 21 |
|
| 22 |
# ----------------------------
|
|
@@ -82,9 +87,6 @@ def run_ai_inference(diff: str) -> str:
|
|
| 82 |
"""
|
| 83 |
Sends the code diff to Hugging Face Inference API to get the review.
|
| 84 |
"""
|
| 85 |
-
if not HF_API_KEY:
|
| 86 |
-
raise RuntimeError("Hugging Face API key is not set.")
|
| 87 |
-
|
| 88 |
# Better prompt for meaningful completions
|
| 89 |
prompt = f"""# Code Review
|
| 90 |
|
|
|
|
| 6 |
import json
|
| 7 |
from fastapi.responses import HTMLResponse
|
| 8 |
import requests
|
| 9 |
+
import os
|
| 10 |
|
| 11 |
|
| 12 |
# ----------------------------
|
|
|
|
| 16 |
MODEL_NAME = "Salesforce/codegen-350M-mono"
|
| 17 |
DEVICE = "cuda" if torch.cuda.is_available() else "cpu"
|
| 18 |
|
| 19 |
+
# Remove hardcoded API key and use an environment variable
|
| 20 |
+
HF_API_KEY = os.getenv("HF_API_KEY")
|
| 21 |
+
|
| 22 |
+
if not HF_API_KEY:
|
| 23 |
+
raise RuntimeError("Hugging Face API key is not set. Please set the HF_API_KEY environment variable.")
|
| 24 |
+
|
| 25 |
HF_MODEL_NAME = "bigcode/starcoder" # Replace with the best model for code review
|
| 26 |
|
| 27 |
# ----------------------------
|
|
|
|
| 87 |
"""
|
| 88 |
Sends the code diff to Hugging Face Inference API to get the review.
|
| 89 |
"""
|
|
|
|
|
|
|
|
|
|
| 90 |
# Better prompt for meaningful completions
|
| 91 |
prompt = f"""# Code Review
|
| 92 |
|