Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,8 +1,5 @@
|
|
| 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
|
|
@@ -23,62 +20,31 @@ def get_exam_data():
|
|
| 23 |
df['Exam Date'] = pd.to_datetime(df['Exam Date'])
|
| 24 |
return df
|
| 25 |
|
| 26 |
-
#
|
| 27 |
-
app = dash.Dash(__name__)
|
| 28 |
-
|
| 29 |
df = get_exam_data()
|
| 30 |
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
])
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
)
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 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 |
-
def launch_dash():
|
| 72 |
-
app.run_server(debug=True, use_reloader=False)
|
| 73 |
-
|
| 74 |
-
# Create a Gradio interface to launch the Dash app
|
| 75 |
-
interface = gr.Interface(
|
| 76 |
-
fn=launch_dash,
|
| 77 |
-
inputs=[],
|
| 78 |
-
outputs=gr.HTML(value="Launching Dash App..."), # Minimal output to satisfy Gradio
|
| 79 |
-
title="Indian Government Exams Calendar",
|
| 80 |
-
description="Explore upcoming Indian government exams on a month-wise calendar."
|
| 81 |
-
)
|
| 82 |
|
|
|
|
| 83 |
if __name__ == "__main__":
|
| 84 |
-
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import pandas as pd
|
|
|
|
|
|
|
|
|
|
| 3 |
import plotly.express as px
|
| 4 |
|
| 5 |
# Function to get exam data
|
|
|
|
| 20 |
df['Exam Date'] = pd.to_datetime(df['Exam Date'])
|
| 21 |
return df
|
| 22 |
|
| 23 |
+
# Load exam data
|
|
|
|
|
|
|
| 24 |
df = get_exam_data()
|
| 25 |
|
| 26 |
+
# Function to filter exams by month and generate plot
|
| 27 |
+
def filter_exams(month_year):
|
| 28 |
+
filtered_df = df[df['Exam Date'].dt.strftime('%B %Y') == month_year]
|
| 29 |
+
if not filtered_df.empty:
|
| 30 |
+
fig = px.timeline(filtered_df, x_start="Exam Date", x_end="Exam Date", y="Exam Name", color="Exam Name", hover_data=["Details"])
|
| 31 |
+
fig.update_layout(xaxis_title="Date", yaxis_title="Exam")
|
| 32 |
+
return fig, f"Exams scheduled for {month_year}"
|
| 33 |
+
else:
|
| 34 |
+
return None, f"No exams scheduled for {month_year}"
|
| 35 |
+
|
| 36 |
+
# List of unique months in the dataset
|
| 37 |
+
months = df['Exam Date'].dt.strftime('%B %Y').unique().tolist()
|
| 38 |
+
|
| 39 |
+
# Gradio Interface
|
| 40 |
+
with gr.Blocks() as demo:
|
| 41 |
+
gr.Markdown("# Indian Government Exams Calendar")
|
| 42 |
+
month_dropdown = gr.Dropdown(choices=months, label="Select Month")
|
| 43 |
+
plot_output = gr.Plot(label="Exam Timeline")
|
| 44 |
+
text_output = gr.Textbox(label="Exam Details")
|
| 45 |
+
|
| 46 |
+
month_dropdown.change(fn=filter_exams, inputs=month_dropdown, outputs=[plot_output, text_output])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
|
| 48 |
+
# Launch the Gradio app
|
| 49 |
if __name__ == "__main__":
|
| 50 |
+
demo.launch()
|