Spaces:
Sleeping
Sleeping
Download backend/graders.py from PROSTLE/StockSense-AI: direct link, hf CLI and curl.
- Browser
- Download file 1.39 kB
-
https://huggingface.co/spaces/PROSTLE/StockSense-AI/resolve/main/backend/graders.py
- Command line
-
hf download hf://spaces/PROSTLE/StockSense-AI/backend/graders.py
-
curl -L -o graders.py https://huggingface.co/spaces/PROSTLE/StockSense-AI/resolve/main/backend/graders.py
1.39 kB
| """ | |
| 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 | |