Download app.py from tykimos/countvis: direct link, hf CLI and curl.
- Browser
- Download file 1.18 kB
-
https://huggingface.co/spaces/tykimos/countvis/resolve/main/app.py
- Command line
-
hf download hf://spaces/tykimos/countvis/app.py
-
curl -L -o app.py https://huggingface.co/spaces/tykimos/countvis/resolve/main/app.py
1.18 kB
| import gradio as gr | |
| import matplotlib.pyplot as plt | |
| from matplotlib.dates import date2num | |
| import numpy as np | |
| import io | |
| from PIL import Image | |
| import pandas as pd | |
| def countvis(fobj): | |
| df = pd.read_csv(fobj.name, sep=",") | |
| dates = pd.to_datetime(df['date']).dt.date.tolist() | |
| dates.sort() | |
| # Get some auxilliary values | |
| min_date = date2num(dates[0]) | |
| max_date = date2num(dates[-1]) | |
| days = int(max_date - min_date + 1) | |
| # Initialize X and Y axes | |
| x = np.arange(min_date, max_date + 1) | |
| y = np.zeros(days) | |
| # Iterate over dates, increase registration array | |
| for date in dates: | |
| index = int(date2num(date) - min_date) | |
| y[index] += 1 | |
| y_sum = np.cumsum(y) | |
| # Plot | |
| plt.figure(dpi=200) | |
| plt.plot_date(x, y_sum, xdate=True, ydate=False, ls='-', ms=0, color='#16171E') | |
| plt.fill_between(x, 0, y_sum, facecolor='#D0F3FF') | |
| plt.xticks(rotation=15) | |
| plt.title('Cumulative Growth') | |
| img_buf = io.BytesIO() | |
| plt.savefig(img_buf, format='png') | |
| im = Image.open(img_buf) | |
| return im | |
| iface = gr.Interface(fn=countvis, inputs="file", outputs="image", allow_flagging="never") | |
| iface.launch(debug="True") |