Spaces:
Build error
Build error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import pandas as pd
|
| 3 |
+
import datetime
|
| 4 |
+
|
| 5 |
+
# Sample Exam Data
|
| 6 |
+
exam_data = {
|
| 7 |
+
"Exam Name": ["NEET", "JEE Main", "CAT", "UPSC CSE", "SSC CGL"],
|
| 8 |
+
"Date": ["2024-05-07", "2024-06-18", "2024-11-28", "2024-06-02", "2024-07-15"],
|
| 9 |
+
"Details": [
|
| 10 |
+
"National Eligibility cum Entrance Test (NEET) for medical aspirants.",
|
| 11 |
+
"Joint Entrance Examination (JEE) for engineering aspirants.",
|
| 12 |
+
"Common Admission Test (CAT) for MBA admissions.",
|
| 13 |
+
"Union Public Service Commission (UPSC) Civil Services Examination.",
|
| 14 |
+
"Staff Selection Commission (SSC) Combined Graduate Level Examination."
|
| 15 |
+
]
|
| 16 |
+
}
|
| 17 |
+
|
| 18 |
+
# Convert data into a DataFrame
|
| 19 |
+
exam_df = pd.DataFrame(exam_data)
|
| 20 |
+
exam_df['Date'] = pd.to_datetime(exam_df['Date'])
|
| 21 |
+
|
| 22 |
+
# Home Page
|
| 23 |
+
def home():
|
| 24 |
+
return """
|
| 25 |
+
<h1>Welcome to TH EDge</h1>
|
| 26 |
+
<p>Your one-stop destination for all educational news, exams, and resources.</p>
|
| 27 |
+
<h2>Sections</h2>
|
| 28 |
+
<ul>
|
| 29 |
+
<li><a href="/exam_calendar">Exam Calendar</a></li>
|
| 30 |
+
<li><a href="#">Study Resources</a></li>
|
| 31 |
+
<li><a href="#">Results</a></li>
|
| 32 |
+
<li><a href="#">Career Guidance</a></li>
|
| 33 |
+
</ul>
|
| 34 |
+
"""
|
| 35 |
+
|
| 36 |
+
# Exam Calendar Page
|
| 37 |
+
def exam_calendar(selected_date=None):
|
| 38 |
+
if selected_date:
|
| 39 |
+
selected_date = pd.to_datetime(selected_date)
|
| 40 |
+
filtered_df = exam_df[exam_df['Date'] >= selected_date]
|
| 41 |
+
else:
|
| 42 |
+
filtered_df = exam_df
|
| 43 |
+
|
| 44 |
+
exam_table = filtered_df.to_html(index=False)
|
| 45 |
+
|
| 46 |
+
return f"""
|
| 47 |
+
<h1>Exam Calendar</h1>
|
| 48 |
+
<p>View upcoming exams and important dates.</p>
|
| 49 |
+
<form method="post">
|
| 50 |
+
<label for="date">Select a date:</label>
|
| 51 |
+
<input type="date" id="date" name="selected_date">
|
| 52 |
+
<input type="submit" value="Search">
|
| 53 |
+
</form>
|
| 54 |
+
{exam_table}
|
| 55 |
+
<br>
|
| 56 |
+
<a href="/">Back to Home</a>
|
| 57 |
+
"""
|
| 58 |
+
|
| 59 |
+
# Gradio App Interface
|
| 60 |
+
def app_interface(request: gr.Request):
|
| 61 |
+
route = request.url.split("/")[-1]
|
| 62 |
+
|
| 63 |
+
if route == "exam_calendar":
|
| 64 |
+
if request.method == "POST":
|
| 65 |
+
selected_date = request.POST.get('selected_date')
|
| 66 |
+
return exam_calendar(selected_date)
|
| 67 |
+
else:
|
| 68 |
+
return exam_calendar()
|
| 69 |
+
else:
|
| 70 |
+
return home()
|
| 71 |
+
|
| 72 |
+
# Launching the Gradio interface
|
| 73 |
+
iface = gr.Interface(
|
| 74 |
+
fn=app_interface,
|
| 75 |
+
inputs=None,
|
| 76 |
+
outputs="html",
|
| 77 |
+
server_name="localhost",
|
| 78 |
+
server_port=7860
|
| 79 |
+
)
|
| 80 |
+
|
| 81 |
+
iface.launch()
|