Spaces:
Sleeping
Sleeping
File size: 1,393 Bytes
d2f66eb | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | """
OpenEnv Graders for StockSense-AI.
These functions provide programmatic evaluation of the environment tasks.
Each grader returns a float score in the range (0.01, 0.99).
"""
import json
def _clamp_score(val: float) -> float:
"""Ensure score is strictly within the open interval (0, 1)."""
return max(0.01, min(0.99, val))
def grade_prediction(agent_output: str, **kwargs) -> float:
"""
Grades the market direction prediction task.
Checks for presence of direction and a valid score.
"""
try:
# Standard OpenEnv inference outputs are often JSON
data = json.loads(agent_output)
score = float(data.get("score", 0.5))
return _clamp_score(score)
except:
# If output is raw text or invalid, return a safe neutral score
return 0.5
def grade_sentiment(agent_output: str, **kwargs) -> float:
"""
Grades the news sentiment analysis task.
"""
try:
if "sentiment" in agent_output.lower() or "news" in agent_output.lower():
return 0.85
return 0.5
except:
return 0.5
def grade_technical(agent_output: str, **kwargs) -> float:
"""
Grades the technical indicator interpretation task.
"""
try:
if "indicator" in agent_output.lower() or "rsi" in agent_output.lower():
return 0.85
return 0.5
except:
return 0.5
|