Spaces:
Running
Running
Download plot_graph.py from shriom23/MedFlow-OpenEnv: direct link, hf CLI and curl.
- Browser
- Download file 998 Bytes
-
https://huggingface.co/spaces/shriom23/MedFlow-OpenEnv/resolve/main/plot_graph.py
- Command line
-
hf download hf://spaces/shriom23/MedFlow-OpenEnv/plot_graph.py
-
curl -L -o plot_graph.py https://huggingface.co/spaces/shriom23/MedFlow-OpenEnv/resolve/main/plot_graph.py
998 Bytes
| import re | |
| import matplotlib.pyplot as plt | |
| def _read_log_text(path: str) -> str: | |
| # PowerShell redirection often creates UTF-16LE files; fall back to UTF-8. | |
| for enc in ("utf-16", "utf-8", "utf-8-sig"): | |
| try: | |
| with open(path, "r", encoding=enc) as f: | |
| return f.read() | |
| except UnicodeError: | |
| continue | |
| with open(path, "r", errors="ignore") as f: | |
| return f.read() | |
| data = _read_log_text("output.txt") | |
| # extract rewards | |
| rewards = [float(x) for x in re.findall(r"reward=([-0-9.]+)", data)] | |
| if not rewards: | |
| print("No reward values found in output.txt. Re-generate log with: python inference.py ... > output.txt") | |
| raise SystemExit(1) | |
| plt.figure(figsize=(8, 4.5)) | |
| plt.plot(rewards, marker="o", markersize=2, linewidth=1) | |
| plt.title("Reward vs Steps") | |
| plt.xlabel("Steps") | |
| plt.ylabel("Reward") | |
| plt.grid(alpha=0.3) | |
| plt.tight_layout() | |
| plt.savefig("reward_plot.png") | |
| print(f"Graph saved as reward_plot.png (points={len(rewards)})") |