dindizz commited on
Commit
c9ef176
·
verified ·
1 Parent(s): 5f0c0e9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +64 -60
app.py CHANGED
@@ -1,79 +1,83 @@
1
  import gradio as gr
2
  import pandas as pd
 
 
 
3
  import plotly.express as px
4
- from datetime import datetime
5
 
 
6
  def get_exam_data():
7
- # Initial list of exams from the PDF
8
  exams = [
9
- {"Exam Name": "Junior Engineer (Civil, Mechanical, Electrical and Quantity Surveying & Contracts) Examination, 2024", "Exam Date": "05-Jun-2024"},
10
- {"Exam Name": "Selection Post Examination, Phase-XII, 2024", "Exam Date": "20-Jun-2024"},
11
- {"Exam Name": "Sub-Inspector in Delhi Police and Central Armed Police Forces Examination, 2024", "Exam Date": "27-Jun-2024"},
12
- {"Exam Name": "Combined Higher Secondary (10+2) Level Examination, 2024", "Exam Date": "01-Jul-2024"},
13
- {"Exam Name": "Combined Graduate Level Examination, 2024", "Exam Date": "Sep-Oct, 2024"},
14
- {"Exam Name": "Multi Tasking (Non-Technical) Staff, and Havaldar (CBIC & CBN) Examination-2024", "Exam Date": "Oct-Nov, 2024"},
15
- {"Exam Name": "Stenographer Grade ‘C’ & ‘D’ Examination, 2024", "Exam Date": "Oct-Nov, 2024"},
16
- {"Exam Name": "Junior Hindi Translator, Junior Translator and Senior Hindi Translator Examination, 2024", "Exam Date": "Oct-Nov, 2024"},
17
- {"Exam Name": "Constables (GD) in Central Armed Police Forces (CAPFs), NIA, SSF and Rifleman (GD) in Assam Rifles Examination, 2025", "Exam Date": "Jan-Feb, 2025"},
18
  ]
19
 
20
- # Additional exams from the Excel sheet
21
- additional_exams = [
22
- {"Exam Name": "SSC CGL - Common Graduate Level", "Exam Date": "Likely July 2024*"},
23
- {"Exam Name": "SSC MTS - Multi-Tasking (Non-Technical) Staff", "Exam Date": "Likely September 2024*"},
24
- {"Exam Name": "SSC CPO - Central Police Organization", "Exam Date": "Likely August 2024*"},
25
- {"Exam Name": "SSC CHSL - Combined Higher Secondary Level", "Exam Date": "Likely March 2024*"},
26
- {"Exam Name": "SSC Selection Posts", "Exam Date": "Likely November 2024*"},
27
- ]
28
-
29
- # Combine the initial and additional exams
30
- exams.extend(additional_exams)
31
-
32
- # Convert the data into a DataFrame
33
  df = pd.DataFrame(exams)
34
-
35
- # Extract actual dates for plotting
36
- df['Plot Date'] = pd.to_datetime(df['Exam Date'].str.extract(r'(\d{2}-[A-Za-z]+-\d{4})')[0], errors='coerce', format='%d-%b-%Y')
37
-
38
  return df
39
 
40
- def filter_exams(exam_name, month):
41
- df = get_exam_data()
42
-
43
- if exam_name:
44
- df = df[df['Exam Name'] == exam_name]
45
-
46
- if month:
47
- df = df[df['Plot Date'].dt.month == month]
48
-
49
- return df
50
 
51
- def create_calendar(exam_name=None, month=None):
52
- df = filter_exams(exam_name, month)
53
-
54
- fig = px.scatter(df, x="Plot Date", y="Exam Name",
55
- hover_data=['Exam Name', 'Exam Date'],
56
- title="Exam Calendar",
57
- labels={"Plot Date": "Date", "Exam Name": "Exam"},
58
- height=600)
59
-
60
- fig.update_layout(xaxis_title="Date", yaxis_title="Exam", xaxis=dict(showgrid=False))
61
- return fig
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
62
 
63
- # Get the list of unique exam names for the dropdown
64
- exam_names = get_exam_data()['Exam Name'].unique().tolist()
65
- exam_names.insert(0, "All Exams") # Add an option to view all exams
66
 
67
- # Create the Gradio interface with dropdown for exam filter and calendar view
68
  interface = gr.Interface(
69
- fn=create_calendar,
70
- inputs=[
71
- gr.Dropdown(choices=exam_names, label="Filter by Exam Name"),
72
- gr.Slider(1, 12, step=1, label="Filter by Month (1 = January, 12 = December)")
73
- ],
74
- outputs=gr.Plot(label="Exam Calendar"),
75
  title="Indian Government Exams Calendar",
76
- description="An interactive calendar for Indian entrance exams. Use this tool to filter and view exams on a calendar!"
77
  )
78
 
79
  if __name__ == "__main__":
 
1
  import gradio as gr
2
  import pandas as pd
3
+ import dash
4
+ from dash import dcc, html
5
+ from dash.dependencies import Input, Output
6
  import plotly.express as px
 
7
 
8
+ # Function to get exam data
9
  def get_exam_data():
 
10
  exams = [
11
+ {"Exam Name": "Junior Engineer (Civil, Mechanical, Electrical and Quantity Surveying & Contracts) Examination, 2024", "Exam Date": "2024-06-05", "Details": "Paper-I (CBE)*"},
12
+ {"Exam Name": "Selection Post Examination, Phase-XII, 2024", "Exam Date": "2024-06-20", "Details": "Phase-XII, 2024"},
13
+ {"Exam Name": "Sub-Inspector in Delhi Police and Central Armed Police Forces Examination, 2024", "Exam Date": "2024-06-27", "Details": "Paper-I (CBE)*"},
14
+ {"Exam Name": "Combined Higher Secondary (10+2) Level Examination, 2024", "Exam Date": "2024-07-01", "Details": "Tier-I (CBE)*"},
15
+ {"Exam Name": "Combined Graduate Level Examination, 2024", "Exam Date": "2024-09-01", "Details": "Tier-I (CBE)*"},
16
+ {"Exam Name": "Multi Tasking (Non-Technical) Staff, and Havaldar (CBIC & CBN) Examination-2024", "Exam Date": "2024-10-01", "Details": "CBE*"},
17
+ {"Exam Name": "Stenographer Grade ‘C’ & ‘D’ Examination, 2024", "Exam Date": "2024-10-15", "Details": "CBE*"},
18
+ {"Exam Name": "Junior Hindi Translator, Junior Translator and Senior Hindi Translator Examination, 2024", "Exam Date": "2024-10-25", "Details": "Paper-I (CBE)*"},
19
+ {"Exam Name": "Constables (GD) in Central Armed Police Forces (CAPFs), NIA, SSF and Rifleman (GD) in Assam Rifles Examination, 2025", "Exam Date": "2025-01-15", "Details": "CBE*"},
20
  ]
21
 
 
 
 
 
 
 
 
 
 
 
 
 
 
22
  df = pd.DataFrame(exams)
23
+ df['Exam Date'] = pd.to_datetime(df['Exam Date'])
 
 
 
24
  return df
25
 
26
+ # Dash App
27
+ app = dash.Dash(__name__)
 
 
 
 
 
 
 
 
28
 
29
+ df = get_exam_data()
30
+
31
+ app.layout = html.Div([
32
+ dcc.DatePickerRange(
33
+ id='date-picker-range',
34
+ min_date_allowed=df['Exam Date'].min(),
35
+ max_date_allowed=df['Exam Date'].max(),
36
+ initial_visible_month=df['Exam Date'].min(),
37
+ start_date=df['Exam Date'].min(),
38
+ end_date=df['Exam Date'].max()
39
+ ),
40
+ html.Div(id='output-container-date-picker-range'),
41
+ html.Div(id='exam-details', style={'marginTop': 20})
42
+ ])
43
+
44
+ @app.callback(
45
+ Output('output-container-date-picker-range', 'children'),
46
+ [Input('date-picker-range', 'start_date'),
47
+ Input('date-picker-range', 'end_date')]
48
+ )
49
+ def update_output(start_date, end_date):
50
+ dff = df[(df['Exam Date'] >= start_date) & (df['Exam Date'] <= end_date)]
51
+ if dff.empty:
52
+ return "No exams scheduled for the selected period."
53
+ return dcc.Graph(
54
+ id='calendar',
55
+ figure=px.timeline(dff, x_start="Exam Date", x_end="Exam Date", y="Exam Name",
56
+ color="Exam Name", hover_data=["Details"],
57
+ title="Exams Scheduled")
58
+ )
59
+
60
+ @app.callback(
61
+ Output('exam-details', 'children'),
62
+ [Input('calendar', 'clickData')]
63
+ )
64
+ def display_exam_details(clickData):
65
+ if clickData:
66
+ exam_name = clickData['points'][0]['y']
67
+ details = df[df['Exam Name'] == exam_name]['Details'].values[0]
68
+ return f"Details for {exam_name}: {details}"
69
+ return "Click on an exam to see the details."
70
 
71
+ # Gradio Interface to launch Dash App
72
+ def launch_dash():
73
+ app.run_server(debug=True, use_reloader=False)
74
 
 
75
  interface = gr.Interface(
76
+ fn=launch_dash,
77
+ inputs=[],
78
+ outputs=[],
 
 
 
79
  title="Indian Government Exams Calendar",
80
+ description="Explore upcoming Indian government exams on a month-wise calendar."
81
  )
82
 
83
  if __name__ == "__main__":