tykimos commited on
Commit
3689021
·
1 Parent(s): 8414986

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +43 -4
app.py CHANGED
@@ -1,7 +1,46 @@
1
  import gradio as gr
 
 
 
 
 
 
2
 
3
- def greet(name):
4
- return "Hello " + name + "!!"
5
 
6
- iface = gr.Interface(fn=greet, inputs="text", outputs="text")
7
- iface.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
+ import matplotlib.pyplot as plt
3
+ from matplotlib.dates import date2num
4
+ import numpy as np
5
+ import io
6
+ from PIL import Image
7
+ import pandas as pd
8
 
9
+ def countvis(fobj):
 
10
 
11
+ df = pd.read_csv(fobj.name, sep=",")
12
+
13
+ dates = pd.to_datetime(df['date']).dt.date.tolist()
14
+ dates.sort()
15
+
16
+ # Get some auxilliary values
17
+ min_date = date2num(dates[0])
18
+ max_date = date2num(dates[-1])
19
+ days = int(max_date - min_date + 1)
20
+
21
+ # Initialize X and Y axes
22
+ x = np.arange(min_date, max_date + 1)
23
+ y = np.zeros(days)
24
+
25
+ # Iterate over dates, increase registration array
26
+ for date in dates:
27
+ index = int(date2num(date) - min_date)
28
+ y[index] += 1
29
+ y_sum = np.cumsum(y)
30
+
31
+ # Plot
32
+ plt.figure(dpi=200)
33
+ plt.plot_date(x, y_sum, xdate=True, ydate=False, ls='-', ms=0, color='#16171E')
34
+ plt.fill_between(x, 0, y_sum, facecolor='#D0F3FF')
35
+ plt.xticks(rotation=45)
36
+ plt.title('Cumulative Growth')
37
+
38
+ img_buf = io.BytesIO()
39
+ plt.savefig(img_buf, format='png')
40
+ im = Image.open(img_buf)
41
+
42
+ return im
43
+
44
+ iface = gr.Interface(fn=countvis, inputs="file", outputs="image", allow_flagging="never")
45
+
46
+ iface.launch(debug="True")