File size: 4,083 Bytes
18ea979
 
a6008f2
18ea979
a6008f2
18ea979
a6008f2
 
d912e0a
a6008f2
 
18ea979
 
 
 
 
a6008f2
18ea979
d912e0a
 
a6008f2
 
 
 
 
 
 
 
 
 
 
 
 
d912e0a
78b53d7
18ea979
a6008f2
 
d912e0a
a6008f2
d912e0a
a6008f2
d912e0a
 
 
a6008f2
78b53d7
a6008f2
 
 
ad58576
 
 
 
a6008f2
 
 
cba9eb5
a6008f2
 
ad58576
 
 
a6008f2
ad58576
a6008f2
78b53d7
a6008f2
78b53d7
 
 
 
ad58576
 
78b53d7
 
 
 
 
 
 
 
 
 
ad58576
 
ffd1453
ad58576
18ea979
 
a6008f2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import gradio as gr
import pandas as pd
import os

# Function to load the dataset
def load_data():
    if os.path.exists('chapter1_english_9th.xlsx'):
        dataset = pd.read_excel('chapter1_english_9th.xlsx', sheet_name=None)
        print(f"Dataset loaded successfully. Sheets available: {dataset.keys()}")  # Debugging line
    else:
        raise FileNotFoundError("Dataset file not found! Please upload the 'chapter1_english_9th.xlsx' file.")
    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):
    print(f"Selected Class: {selected_class}, Subject: {selected_subject}, Chapter: {selected_chapter}, Content Type: {content_type}")  # Debugging line

    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 2':
        sheet_mapping = {
            'Short Questions': 'Sheet4',
            'Synonyms and Urdu Meaning': 'Sheet5',
            'Grammar Identification': 'Sheet6'
        }
    else:
        print("No matching data for the given selection.")  # Debugging line
        return None
    
    sheet_name = sheet_mapping.get(content_type)

    # Check if sheet name exists
    if sheet_name in dataset:
        print(f"Found data for {sheet_name}")  # Debugging line
        return dataset[sheet_name]
    else:
        print(f"Sheet '{sheet_name}' not found in dataset.")  # Debugging line
        return None

# Groq Model Processing (Placeholder function)
def groq_process_data(content):
    return content.head()  # Returning first 5 rows for illustration

# Gradio interface function for new result page
def result_page(content):
    return content

# Gradio interface function
def gradio_interface(selected_class, selected_subject, selected_chapter, content_type):
    content = get_content(selected_class, selected_subject, selected_chapter, content_type)
    
    if content is not None and not content.empty:
        processed_content = groq_process_data(content)
        # Launching a new page with the result
        gr.Interface(fn=result_page, inputs=gr.Dataframe(value=processed_content), outputs=gr.Dataframe()).launch()
        return processed_content
    else:
        return "No data available currently."

# Define the Gradio interface with attractive layout and fresh output page
def run_app():
    with gr.Blocks() as demo:
        # Header section
        gr.Markdown("# Educational Content Access App")
        gr.Markdown("### Select options to view educational content.")

        # Input section: Using card-style layout for a neat appearance
        with gr.Row():
            with gr.Column(scale=1):
                selected_class = gr.Dropdown(label="Select Class", choices=["Class 9", "Class 10", "Class 11", "Class 12"], interactive=True)
                selected_subject = gr.Dropdown(label="Select Subject", choices=["Computer", "English", "Physics", "Chemistry", "Math"], interactive=True)
                selected_chapter = gr.Dropdown(label="Select Chapter", choices=[f"Chapter {i}" for i in range(1, 13)], interactive=True)
                content_type = gr.Dropdown(label="Select Content Type", choices=["Short Questions", "Synonyms and Urdu Meaning", "Grammar Identification"], interactive=True)

        # Submit Button to generate content
        submit_button = gr.Button("Show Content", variant="primary")

        # Connecting the button to the output, results will be shown on a new page
        submit_button.click(gradio_interface, inputs=[selected_class, selected_subject, selected_chapter, content_type], outputs=[])

    demo.launch(share=True)  # Launch the app with the share parameter to open it on a new page

# Run the app
run_app()