Spaces:
Sleeping
Sleeping
Download webapp/services/charts.py from PeaceAbolisher/Model_Lab_Deployment: direct link, hf CLI and curl.
- Browser
- Download file 617 Bytes
-
https://huggingface.co/spaces/PeaceAbolisher/Model_Lab_Deployment/resolve/main/webapp/services/charts.py
- Command line
-
hf download hf://spaces/PeaceAbolisher/Model_Lab_Deployment/webapp/services/charts.py
-
curl -L -o charts.py https://huggingface.co/spaces/PeaceAbolisher/Model_Lab_Deployment/resolve/main/webapp/services/charts.py
617 Bytes
| # webapp/services/charts.py | |
| import io, base64 | |
| import matplotlib | |
| matplotlib.use('Agg') | |
| import matplotlib.pyplot as plt | |
| import numpy as np | |
| def preds_hist_data_url(preds) -> str: | |
| buf = io.BytesIO() | |
| plt.figure(figsize=(6,4)) | |
| try: | |
| plt.hist(preds, bins=3) | |
| except Exception: | |
| vals, counts = np.unique(preds, return_counts=True) | |
| plt.bar([str(v) for v in vals], counts) | |
| plt.title('Predictions') | |
| plt.tight_layout() | |
| plt.savefig(buf, format='png') | |
| plt.close() | |
| buf.seek(0) | |
| b64 = base64.b64encode(buf.read()).decode('utf-8') | |
| return f'data:image/png;base64,{b64}' | |