tariqm603 commited on
Commit
78b53d7
·
verified ·
1 Parent(s): cba9eb5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -26
app.py CHANGED
@@ -4,7 +4,6 @@ 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:
@@ -16,7 +15,6 @@ 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',
@@ -30,21 +28,17 @@ def get_content(selected_class, selected_subject, selected_chapter, content_type
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
@@ -52,30 +46,38 @@ def gradio_interface(selected_class, selected_subject, selected_chapter, content
52
  content = get_content(selected_class, selected_subject, selected_chapter, content_type)
53
 
54
  if content is not None and not content.empty:
55
- # Process the content using Groq (or simulate processing)
56
  processed_content = groq_process_data(content)
57
  return processed_content
58
  else:
59
- # Return message when no data is found
60
  return "No data available currently."
61
 
62
- # Define the Gradio interface
63
  def run_app():
64
- # Set up the Gradio interface
65
- interface = gr.Interface(
66
- fn=gradio_interface,
67
- inputs=[
68
- gr.Dropdown(label="Select Class", choices=["Class 9", "Class 10", "Class 11", "Class 12"]),
69
- gr.Dropdown(label="Select Subject", choices=["Computer", "English", "Physics", "Chemistry", "Math"]),
70
- gr.Dropdown(label="Select Chapter", choices=[f"Chapter {i}" for i in range(1, 13)]),
71
- gr.Dropdown(label="Select Content Type", choices=["Short Questions", "Synonyms and Urdu Meaning", "Grammar Identification"])
72
- ],
73
- outputs="text", # Display result as text (to show message or processed content)
74
- live=False, # Disable live updates
75
- title="Educational Content Access App",
76
- description="Select the class, subject, chapter, and content type to view educational content. If no data is available for the selected options, a message will be displayed."
77
- )
78
- interface.launch()
 
 
 
 
 
 
 
 
 
 
79
 
80
  # Run the app
81
  run_app()
 
4
 
5
  # Function to load the dataset
6
  def load_data():
 
7
  if os.path.exists('chapter1_english_9th.xlsx'):
8
  dataset = pd.read_excel('chapter1_english_9th.xlsx', sheet_name=None)
9
  else:
 
15
 
16
  # Function to retrieve content based on exact selections
17
  def get_content(selected_class, selected_subject, selected_chapter, content_type):
 
18
  if selected_class == 'Class 9' and selected_subject == 'English' and selected_chapter == 'Chapter 1':
19
  sheet_mapping = {
20
  'Short Questions': 'Sheet1',
 
28
  'Grammar Identification': 'Sheet6'
29
  }
30
  else:
31
+ return None
32
 
33
  sheet_name = sheet_mapping.get(content_type)
34
 
 
35
  if sheet_name in dataset:
36
  return dataset[sheet_name]
37
 
38
  return None
39
 
40
+ # Groq Model Processing (Placeholder function)
 
41
  def groq_process_data(content):
 
 
42
  return content.head() # Returning first 5 rows for illustration
43
 
44
  # Gradio interface function
 
46
  content = get_content(selected_class, selected_subject, selected_chapter, content_type)
47
 
48
  if content is not None and not content.empty:
 
49
  processed_content = groq_process_data(content)
50
  return processed_content
51
  else:
 
52
  return "No data available currently."
53
 
54
+ # Define the Gradio interface with attractive layout and fresh output page
55
  def run_app():
56
+ with gr.Blocks() as demo:
57
+ # Header section
58
+ gr.Markdown("# Educational Content Access App")
59
+ gr.Markdown("### Select options to view educational content.")
60
+
61
+ # Input section: Using card-style layout for a neat appearance
62
+ with gr.Row():
63
+ with gr.Column(scale=1):
64
+ selected_class = gr.Dropdown(label="Select Class", choices=["Class 9", "Class 10", "Class 11", "Class 12"], interactive=True)
65
+ selected_subject = gr.Dropdown(label="Select Subject", choices=["Computer", "English", "Physics", "Chemistry", "Math"], interactive=True)
66
+ selected_chapter = gr.Dropdown(label="Select Chapter", choices=[f"Chapter {i}" for i in range(1, 13)], interactive=True)
67
+ content_type = gr.Dropdown(label="Select Content Type", choices=["Short Questions", "Synonyms and Urdu Meaning", "Grammar Identification"], interactive=True)
68
+
69
+ # Submit Button to generate content
70
+ submit_button = gr.Button("Show Content", variant="primary")
71
+
72
+ # Output Section: This will display the result on a new page when content is found
73
+ output_area = gr.TabbedInterface([
74
+ gr.Tab("Results", gr.Dataframe()),
75
+ gr.Tab("No Data Available", gr.Textbox())
76
+ ])
77
+
78
+ submit_button.click(gradio_interface, inputs=[selected_class, selected_subject, selected_chapter, content_type], outputs=[output_area])
79
+
80
+ demo.launch()
81
 
82
  # Run the app
83
  run_app()