File size: 1,176 Bytes
8414986 3689021 8414986 3689021 8414986 3689021 8e8b7aa 3689021 |
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 |
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") |