lbourdois commited on
Commit
1e36ee7
·
verified ·
1 Parent(s): c2918b3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -34
app.py CHANGED
@@ -1,45 +1,41 @@
1
  import gradio as gr
2
  import pandas as pd
3
- from datetime import datetime, timedelta
4
-
5
- # Initialize data
6
- data = {
7
- "Date": pd.date_range(start="2023-01-01", end="2025-12-31", freq="D"),
8
- "Chris": 0,
9
- "Loïck": 0
10
- }
11
-
12
- df = pd.DataFrame(data)
13
-
14
- def update_points(player, points, date):
15
- global df
16
- date = pd.to_datetime(date)
17
- if player == "Chris":
18
- df.loc[df["Date"] == date, "Chris"] += points
19
- else:
20
- df.loc[df["Date"] == date, "Loïck"] += points
21
  return df
22
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
23
  with gr.Blocks() as demo:
24
  gr.Markdown("# Leaderboard")
25
 
26
- with gr.Row():
27
- player = gr.Dropdown(["Chris", "Loïck"], label="Fellow")
28
- points = gr.Number(label="Points", value=1)
29
- date = gr.Textbox(label="Date", value="2023-01-01")
30
- update_btn = gr.Button("Update Points")
31
 
32
- leaderboard = gr.DataFrame(label="Leaderboard", headers=["Date", "Chris", "Loïck"])
33
-
34
- update_btn.click(
35
- fn=update_points,
36
- inputs=[player, points, date],
37
- outputs=leaderboard
38
- )
39
 
40
- demo.load(
41
- fn=lambda: df,
42
- outputs=leaderboard
43
  )
44
 
45
- demo.launch()
 
1
  import gradio as gr
2
  import pandas as pd
3
+
4
+ def read_file():
5
+ df = pd.read_csv("./data.csv")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6
  return df
7
 
8
+ def count_names(df):
9
+ chris_count = (df["First"] == "Chris").sum()
10
+ loick_count = (df["First"] == "Loïck").sum()
11
+ return chris_count, loick_count
12
+
13
+ def determine_goat(chris_count, loick_count):
14
+ if chris_count > loick_count:
15
+ return "The current GOAT is: Chris"
16
+ elif loick_count > chris_count:
17
+ return "The current GOAT is: Loïck"
18
+ else:
19
+ return "The current GOAT is: It's a tie between Chris and Loïck"
20
+
21
+ def process_file():
22
+ df = read_file()
23
+ chris_count, loick_count = count_names(df)
24
+ goat = determine_goat(chris_count, loick_count)
25
+ return df, f"Chris count: {chris_count}, Loïck count: {loick_count}", goat
26
+
27
  with gr.Blocks() as demo:
28
  gr.Markdown("# Leaderboard")
29
 
30
+ process_btn = gr.Button("Process File")
 
 
 
 
31
 
32
+ df_output = gr.DataFrame(label="DataFrame")
33
+ count_output = gr.Textbox(label="Counts")
34
+ goat_output = gr.Textbox(label="Current GOAT")
 
 
 
 
35
 
36
+ process_btn.click(
37
+ fn=process_file,
38
+ outputs=[df_output, count_output, goat_output]
39
  )
40
 
41
+ demo.launch()