Upload folder using huggingface_hub
Browse files- grader.py +4 -4
- inference.py +38 -4
grader.py
CHANGED
|
@@ -26,7 +26,7 @@ def _attempt_quality(rewards):
|
|
| 26 |
return _safe_ratio(positive_attempts, len(rewards))
|
| 27 |
|
| 28 |
|
| 29 |
-
def
|
| 30 |
if score >= 0.9:
|
| 31 |
return f"{category} performance is excellent and highly reliable."
|
| 32 |
if score >= 0.7:
|
|
@@ -41,7 +41,7 @@ def grade_segmentation(app_obs: AppObservation):
|
|
| 41 |
progress_score = _safe_ratio(len(app_obs.objectsFound), total_objects)
|
| 42 |
quality_score = _attempt_quality(app_obs.rewardListSegment)
|
| 43 |
score = _clamp_score((progress_score * 0.7) + (quality_score * 0.3))
|
| 44 |
-
return score,
|
| 45 |
|
| 46 |
|
| 47 |
def grade_placement(app_obs: AppObservation):
|
|
@@ -49,7 +49,7 @@ def grade_placement(app_obs: AppObservation):
|
|
| 49 |
progress_score = _safe_ratio(app_obs.numberPlaced, total_objects)
|
| 50 |
quality_score = _attempt_quality(app_obs.rewardListPlace)
|
| 51 |
score = _clamp_score((progress_score * 0.7) + (quality_score * 0.3))
|
| 52 |
-
return score,
|
| 53 |
|
| 54 |
|
| 55 |
def grade_adjustment(app_obs: AppObservation):
|
|
@@ -58,4 +58,4 @@ def grade_adjustment(app_obs: AppObservation):
|
|
| 58 |
return 0.0, "Adjustment was not attempted."
|
| 59 |
|
| 60 |
score = _attempt_quality(rewards)
|
| 61 |
-
return score,
|
|
|
|
| 26 |
return _safe_ratio(positive_attempts, len(rewards))
|
| 27 |
|
| 28 |
|
| 29 |
+
def feedback(score, category):
|
| 30 |
if score >= 0.9:
|
| 31 |
return f"{category} performance is excellent and highly reliable."
|
| 32 |
if score >= 0.7:
|
|
|
|
| 41 |
progress_score = _safe_ratio(len(app_obs.objectsFound), total_objects)
|
| 42 |
quality_score = _attempt_quality(app_obs.rewardListSegment)
|
| 43 |
score = _clamp_score((progress_score * 0.7) + (quality_score * 0.3))
|
| 44 |
+
return score, feedback(score, "Segmentation")
|
| 45 |
|
| 46 |
|
| 47 |
def grade_placement(app_obs: AppObservation):
|
|
|
|
| 49 |
progress_score = _safe_ratio(app_obs.numberPlaced, total_objects)
|
| 50 |
quality_score = _attempt_quality(app_obs.rewardListPlace)
|
| 51 |
score = _clamp_score((progress_score * 0.7) + (quality_score * 0.3))
|
| 52 |
+
return score, feedback(score, "Placement")
|
| 53 |
|
| 54 |
|
| 55 |
def grade_adjustment(app_obs: AppObservation):
|
|
|
|
| 58 |
return 0.0, "Adjustment was not attempted."
|
| 59 |
|
| 60 |
score = _attempt_quality(rewards)
|
| 61 |
+
return score, feedback(score, "Adjustment")
|
inference.py
CHANGED
|
@@ -3,6 +3,7 @@ from dotenv import load_dotenv
|
|
| 3 |
from openai import OpenAI
|
| 4 |
import json
|
| 5 |
from json import JSONDecodeError
|
|
|
|
| 6 |
from numpy import set_printoptions
|
| 7 |
|
| 8 |
try:
|
|
@@ -24,9 +25,38 @@ except ImportError:
|
|
| 24 |
load_dotenv()
|
| 25 |
set_printoptions(precision=2, suppress=True)
|
| 26 |
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
|
| 31 |
MAX_STEPS = 8
|
| 32 |
TEMPERATURE = 0.2
|
|
@@ -185,6 +215,10 @@ def main() -> None:
|
|
| 185 |
if observation.isDone:
|
| 186 |
break
|
| 187 |
|
| 188 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 189 |
if __name__ == "__main__":
|
| 190 |
main()
|
|
|
|
| 3 |
from openai import OpenAI
|
| 4 |
import json
|
| 5 |
from json import JSONDecodeError
|
| 6 |
+
from urllib.parse import urlparse
|
| 7 |
from numpy import set_printoptions
|
| 8 |
|
| 9 |
try:
|
|
|
|
| 25 |
load_dotenv()
|
| 26 |
set_printoptions(precision=2, suppress=True)
|
| 27 |
|
| 28 |
+
|
| 29 |
+
def _get_env(*names):
|
| 30 |
+
for name in names:
|
| 31 |
+
value = os.getenv(name)
|
| 32 |
+
if value:
|
| 33 |
+
return value.strip().strip("\"'")
|
| 34 |
+
return None
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
def _normalize_api_url(raw_url):
|
| 38 |
+
if not raw_url:
|
| 39 |
+
return None
|
| 40 |
+
|
| 41 |
+
url = raw_url.strip().strip("\"'")
|
| 42 |
+
if "://" not in url:
|
| 43 |
+
url = f"https://{url.lstrip('/')}"
|
| 44 |
+
|
| 45 |
+
parsed = urlparse(url)
|
| 46 |
+
if not parsed.scheme or not parsed.netloc:
|
| 47 |
+
raise RuntimeError(
|
| 48 |
+
"Invalid API base URL. Set API_BASE_URL (or OPENAI_BASE_URL)."
|
| 49 |
+
"URL such as 'https://generativelanguage.googleapis.com/v1beta/openai/'."
|
| 50 |
+
)
|
| 51 |
+
|
| 52 |
+
return url
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
API_URL = _normalize_api_url(
|
| 56 |
+
_get_env("API_BASE_URL", "OPENAI_BASE_URL", "OPENAI_API_BASE")
|
| 57 |
+
)
|
| 58 |
+
MODEL = _get_env("MODEL_NAME", "OPENAI_MODEL")
|
| 59 |
+
API_KEY = _get_env("API_KEY", "OPENAI_API_KEY", "HF_TOKEN")
|
| 60 |
|
| 61 |
MAX_STEPS = 8
|
| 62 |
TEMPERATURE = 0.2
|
|
|
|
| 215 |
if observation.isDone:
|
| 216 |
break
|
| 217 |
|
| 218 |
+
segment = grade_segmentation(observation)
|
| 219 |
+
placing = grade_placement(observation)
|
| 220 |
+
adjust = grade_adjust(observation)
|
| 221 |
+
|
| 222 |
+
|
| 223 |
if __name__ == "__main__":
|
| 224 |
main()
|