tariqm603 commited on
Commit
a6008f2
·
verified ·
1 Parent(s): 40264d3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +60 -43
app.py CHANGED
@@ -1,58 +1,75 @@
1
  import gradio as gr
2
  import pandas as pd
 
3
 
4
- # Load the dataset
5
- # Ensure 'userdataset.csv' is uploaded in the same directory in Hugging Face Spaces
6
  def load_data():
7
- dataset = pd.read_excel('chapter1_english_9th.xlsx', sheet_name=None)
 
 
 
 
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
- sheet_mapping = {
16
- 'Short Questions': 'Sheet1',
17
- 'Synonyms and Urdu Meaning': 'Sheet2',
18
- 'Grammar Identification': 'Sheet3'
19
- }
20
- sheet_name = sheet_mapping.get(content_type)
21
- data = dataset[sheet_name]
22
- # Filter data here if necessary (e.g., based on selected class, subject, chapter)
23
- return data.to_html(index=False) # Return HTML table
24
-
25
- # Function to update content based on inputs
26
- def update_content(selected_class, selected_subject, selected_chapter, selected_content_type):
27
- content = get_content(selected_class, selected_subject, selected_chapter, selected_content_type)
28
- html_output = f"""
29
- <h3>{selected_content_type} for {selected_class} - {selected_subject} - {selected_chapter}</h3>
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
- # Dropdowns for user selection
39
- selected_class = gr.Dropdown(choices=['Class 9', 'Class 10', 'Class 11', 'Class 12'], label="Select Class")
40
- selected_subject = gr.Dropdown(choices=['Computer', 'English', 'Physics', 'Chemistry', 'Math'], label="Select Subject")
41
- selected_chapter = gr.Dropdown(choices=[f'Chapter {i}' for i in range(1, 13)], label="Select Chapter")
42
- selected_content_type = gr.Dropdown(choices=['Short Questions', 'Synonyms and Urdu Meaning', 'Grammar Identification'], label="Select Content Type")
43
-
44
- # Button to display content
45
- display_button = gr.Button("Show Content")
46
 
47
- # HTML output area for displaying content
48
- content_output = gr.HTML()
49
-
50
- # Update content based on button click and user selections
51
- display_button.click(
52
- update_content,
53
- inputs=[selected_class, selected_subject, selected_chapter, selected_content_type],
54
- outputs=content_output
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
55
  )
 
56
 
57
  # Run the app
58
- app.launch()
 
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()