Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,58 +1,75 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import pandas as pd
|
|
|
|
| 3 |
|
| 4 |
-
#
|
| 5 |
-
# Ensure 'userdataset.csv' is uploaded in the same directory in Hugging Face Spaces
|
| 6 |
def load_data():
|
| 7 |
-
dataset
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
return dataset
|
| 9 |
|
| 10 |
# Load the dataset
|
| 11 |
dataset = load_data()
|
| 12 |
|
| 13 |
-
# Function to retrieve content based on selections
|
| 14 |
def get_content(selected_class, selected_subject, selected_chapter, content_type):
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
{content}
|
| 31 |
-
"""
|
| 32 |
-
return html_output
|
| 33 |
-
|
| 34 |
-
# Define the Gradio app layout and interaction
|
| 35 |
-
with gr.Blocks() as app:
|
| 36 |
-
gr.Markdown("# Educational Content Access App")
|
| 37 |
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
# Button to display content
|
| 45 |
-
display_button = gr.Button("Show Content")
|
| 46 |
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
)
|
|
|
|
| 56 |
|
| 57 |
# Run the app
|
| 58 |
-
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import pandas as pd
|
| 3 |
+
import os
|
| 4 |
|
| 5 |
+
# Function to load the dataset
|
|
|
|
| 6 |
def load_data():
|
| 7 |
+
# Ensure the dataset is uploaded to Hugging Face or placed in the correct directory
|
| 8 |
+
if os.path.exists('chapter1_english_9th.xlsx'):
|
| 9 |
+
dataset = pd.read_excel('chapter1_english_9th.xlsx', sheet_name=None)
|
| 10 |
+
else:
|
| 11 |
+
raise FileNotFoundError("Dataset file not found! Please upload the 'chapter1_english_9th.xlsx' file.")
|
| 12 |
return dataset
|
| 13 |
|
| 14 |
# Load the dataset
|
| 15 |
dataset = load_data()
|
| 16 |
|
| 17 |
+
# Function to retrieve content based on exact selections
|
| 18 |
def get_content(selected_class, selected_subject, selected_chapter, content_type):
|
| 19 |
+
# Map combinations of selections to sheet names
|
| 20 |
+
if selected_class == 'Class 9' and selected_subject == 'English' and selected_chapter == 'Chapter 1':
|
| 21 |
+
sheet_mapping = {
|
| 22 |
+
'Short Questions': 'Sheet1',
|
| 23 |
+
'Synonyms and Urdu Meaning': 'Sheet2',
|
| 24 |
+
'Grammar Identification': 'Sheet3'
|
| 25 |
+
}
|
| 26 |
+
elif selected_class == 'Class 10' and selected_subject == 'English' and selected_chapter == 'Chapter 2':
|
| 27 |
+
sheet_mapping = {
|
| 28 |
+
'Short Questions': 'Sheet4',
|
| 29 |
+
'Synonyms and Urdu Meaning': 'Sheet5',
|
| 30 |
+
'Grammar Identification': 'Sheet6'
|
| 31 |
+
}
|
| 32 |
+
else:
|
| 33 |
+
return None # No data available for other combinations
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
|
| 35 |
+
sheet_name = sheet_mapping.get(content_type)
|
| 36 |
+
|
| 37 |
+
# Ensure the sheet exists in the dataset
|
| 38 |
+
if sheet_name in dataset:
|
| 39 |
+
return dataset[sheet_name]
|
|
|
|
|
|
|
|
|
|
| 40 |
|
| 41 |
+
return None
|
| 42 |
+
|
| 43 |
+
# Groq Model Processing (Assumed example function for data processing using Groq)
|
| 44 |
+
# This is just a placeholder function. Replace it with actual Groq processing logic.
|
| 45 |
+
def groq_process_data(content):
|
| 46 |
+
# Example Groq processing
|
| 47 |
+
# Assuming that Groq operates on this content in some form, replace with real Groq API logic
|
| 48 |
+
return content.head() # Returning first 5 rows for illustration
|
| 49 |
+
|
| 50 |
+
# Gradio interface function
|
| 51 |
+
def gradio_interface(selected_class, selected_subject, selected_chapter, content_type):
|
| 52 |
+
content = get_content(selected_class, selected_subject, selected_chapter, content_type)
|
| 53 |
+
if content is not None and not content.empty:
|
| 54 |
+
# Process the content using Groq (or simulate processing)
|
| 55 |
+
processed_content = groq_process_data(content)
|
| 56 |
+
return processed_content
|
| 57 |
+
else:
|
| 58 |
+
return "No data available for the selected options."
|
| 59 |
+
|
| 60 |
+
# Define the Gradio interface
|
| 61 |
+
def run_app():
|
| 62 |
+
interface = gr.Interface(
|
| 63 |
+
fn=gradio_interface,
|
| 64 |
+
inputs=[
|
| 65 |
+
gr.Dropdown(label="Select Class", choices=["Class 9", "Class 10", "Class 11", "Class 12"]),
|
| 66 |
+
gr.Dropdown(label="Select Subject", choices=["Computer", "English", "Physics", "Chemistry", "Math"]),
|
| 67 |
+
gr.Dropdown(label="Select Chapter", choices=[f"Chapter {i}" for i in range(1, 13)]),
|
| 68 |
+
gr.Dropdown(label="Select Content Type", choices=["Short Questions", "Synonyms and Urdu Meaning", "Grammar Identification"])
|
| 69 |
+
],
|
| 70 |
+
outputs="dataframe" # This will display the data as a table
|
| 71 |
)
|
| 72 |
+
interface.launch()
|
| 73 |
|
| 74 |
# Run the app
|
| 75 |
+
run_app()
|