study-assist / app.py
tariqm603's picture
Update app.py
ec4a3fc verified
import streamlit as st
import pandas as pd
# Load the dataset
# Ensure 'chapter1_english_9th.xlsx' is uploaded in the same directory in Hugging Face Spaces
@st.cache_data
def load_data():
# Load all sheets in the Excel file
dataset = pd.read_excel('chapter1_english_9th.xlsx', sheet_name=None)
return dataset
# Load the dataset
dataset = load_data()
# Function to retrieve content based on exact selections
def get_content(selected_class, selected_subject, selected_chapter, content_type):
# Map combinations of selections to sheet names
if selected_class == 'Class 9' and selected_subject == 'English' and selected_chapter == 'Chapter 1':
sheet_mapping = {
'Short Questions': 'Sheet1',
'Synonyms and Urdu Meaning': 'Sheet2',
'Grammar Identification': 'Sheet3'
}
elif selected_class == 'Class 10' and selected_subject == 'English' and selected_chapter == 'Chapter 1':
sheet_mapping = {
'Short Questions': 'Sheet4',
'Synonyms and Urdu Meaning': 'Sheet5',
'Grammar Identification': 'Sheet6'
}
else:
return None # No data available for other combinations
sheet_name = sheet_mapping.get(content_type)
# Ensure the sheet exists in the dataset
if sheet_name in dataset:
return dataset[sheet_name]
return None
# Define the Streamlit app
def run_app():
st.title("Educational Content Access App")
# Class selection
selected_class = st.selectbox("Select Class", ['Class 9', 'Class 10', 'Class 11', 'Class 12'])
# Subject selection
subjects = ['Computer', 'English', 'Physics', 'Chemistry', 'Math']
selected_subject = st.selectbox("Select Subject", subjects)
# Chapter selection
chapters = [f'Chapter {i}' for i in range(1, 13)]
selected_chapter = st.selectbox("Select Chapter", chapters)
# Content Type selection
content_types = ['Short Questions', 'Synonyms and Urdu Meaning', 'Grammar Identification']
selected_content_type = st.selectbox("Select Content Type", content_types)
# Display content based on selections
if st.button("Show Content"):
content = get_content(selected_class, selected_subject, selected_chapter, selected_content_type)
if content is not None and not content.empty:
st.write(f"### {selected_content_type} for {selected_class} - {selected_subject} - {selected_chapter}")
st.write(content)
else:
st.write("No data available for the selected options.")
# Run the app
run_app()