NithyasriVllB commited on
Commit
5fefb8a
·
verified ·
1 Parent(s): d12ad5c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +39 -17
app.py CHANGED
@@ -1,34 +1,56 @@
1
  import gradio as gr
2
  import pandas as pd
3
  import matplotlib.pyplot as plt
 
4
 
5
  # Function to visualize student progress
6
  def visualize_progress(file):
7
- df = pd.read_csv(file.name) # Reading the uploaded CSV file
8
-
9
- plt.figure(figsize=(10,6))
10
- for student in df['student_name'].unique():
11
- student_data = df[df['student_name'] == student]
12
- plt.plot(student_data['date'], student_data['score'], label=student)
13
-
14
- plt.xlabel('Date')
15
- plt.ylabel('Score')
16
- plt.title('Student Progress Over Time')
17
- plt.legend()
18
- plt.grid(True)
19
 
20
- plt.savefig('progress.png') # Save the plot to display it later
21
- return 'progress.png'
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
22
 
23
  # Gradio UI
24
  with gr.Blocks() as demo:
25
  gr.Markdown("# Student Progress Analysis Tool")
26
 
27
- # File input and display output
28
  file_input = gr.File(label="Upload Student Data (CSV)")
29
  output_image = gr.Image(label="Progress Chart")
30
 
31
- # Call the visualize_progress function
32
  file_input.change(visualize_progress, inputs=file_input, outputs=output_image)
33
 
34
- demo.launch()
 
 
1
  import gradio as gr
2
  import pandas as pd
3
  import matplotlib.pyplot as plt
4
+ import os
5
 
6
  # Function to visualize student progress
7
  def visualize_progress(file):
8
+ # Check if the file is a valid CSV file
9
+ if file is None:
10
+ return "No file uploaded!"
 
 
 
 
 
 
 
 
 
11
 
12
+ try:
13
+ # Read the CSV file using pandas
14
+ df = pd.read_csv(file.name)
15
+
16
+ # Check if required columns exist in the CSV
17
+ required_columns = {'student_name', 'date', 'score'}
18
+ if not required_columns.issubset(df.columns):
19
+ return "CSV should contain 'student_name', 'date', and 'score' columns."
20
+
21
+ # Create a progress plot for each student
22
+ plt.figure(figsize=(10, 6))
23
+ for student in df['student_name'].unique():
24
+ student_data = df[df['student_name'] == student]
25
+ plt.plot(student_data['date'], student_data['score'], label=student)
26
+
27
+ # Customize the chart
28
+ plt.xlabel('Date')
29
+ plt.ylabel('Score')
30
+ plt.title('Student Progress Over Time')
31
+ plt.legend()
32
+ plt.grid(True)
33
+
34
+ # Save the plot to a file
35
+ plot_filename = "progress.png"
36
+ plt.savefig(plot_filename)
37
+ plt.close()
38
+
39
+ return plot_filename
40
+
41
+ except Exception as e:
42
+ return f"Error: {e}"
43
 
44
  # Gradio UI
45
  with gr.Blocks() as demo:
46
  gr.Markdown("# Student Progress Analysis Tool")
47
 
48
+ # File input for CSV and display output
49
  file_input = gr.File(label="Upload Student Data (CSV)")
50
  output_image = gr.Image(label="Progress Chart")
51
 
52
+ # Call the visualize_progress function when the file changes
53
  file_input.change(visualize_progress, inputs=file_input, outputs=output_image)
54
 
55
+ # Launch the Gradio app
56
+ demo.launch()