Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -48,15 +48,21 @@ def get_content(selected_class, selected_subject, selected_chapter, content_type
|
|
| 48 |
def groq_process_data(content):
|
| 49 |
return content.head() # Returning first 5 rows for illustration
|
| 50 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
# Gradio interface function
|
| 52 |
def gradio_interface(selected_class, selected_subject, selected_chapter, content_type):
|
| 53 |
content = get_content(selected_class, selected_subject, selected_chapter, content_type)
|
| 54 |
|
| 55 |
if content is not None and not content.empty:
|
| 56 |
processed_content = groq_process_data(content)
|
| 57 |
-
|
|
|
|
|
|
|
| 58 |
else:
|
| 59 |
-
return
|
| 60 |
|
| 61 |
# Define the Gradio interface with attractive layout and fresh output page
|
| 62 |
def run_app():
|
|
@@ -64,8 +70,8 @@ def run_app():
|
|
| 64 |
# Header section
|
| 65 |
gr.Markdown("# Educational Content Access App")
|
| 66 |
gr.Markdown("### Select options to view educational content.")
|
| 67 |
-
|
| 68 |
-
#
|
| 69 |
with gr.Row():
|
| 70 |
with gr.Column(scale=1):
|
| 71 |
selected_class = gr.Dropdown(label="Select Class", choices=["Class 9", "Class 10", "Class 11", "Class 12"], interactive=True)
|
|
@@ -76,35 +82,10 @@ def run_app():
|
|
| 76 |
# Submit Button to generate content
|
| 77 |
submit_button = gr.Button("Show Content", variant="primary")
|
| 78 |
|
| 79 |
-
#
|
| 80 |
-
|
| 81 |
-
with gr.Tab("Results"):
|
| 82 |
-
output_area = gr.Dataframe() # Result Dataframe
|
| 83 |
-
with gr.Tab("No Data Available"):
|
| 84 |
-
output_message = gr.Textbox() # No data message
|
| 85 |
-
|
| 86 |
-
# Initially, hide results and error message
|
| 87 |
-
output_area.visible = False
|
| 88 |
-
output_message.visible = False
|
| 89 |
-
|
| 90 |
-
# Connecting the button to the output
|
| 91 |
-
submit_button.click(gradio_interface, inputs=[selected_class, selected_subject, selected_chapter, content_type], outputs=[output_area, output_message])
|
| 92 |
-
|
| 93 |
-
# Show results only after the button is clicked and hide them initially
|
| 94 |
-
def toggle_output(results, message):
|
| 95 |
-
if results is not None:
|
| 96 |
-
output_area.visible = True
|
| 97 |
-
output_message.visible = False
|
| 98 |
-
return results, ""
|
| 99 |
-
else:
|
| 100 |
-
output_area.visible = False
|
| 101 |
-
output_message.visible = True
|
| 102 |
-
return message,
|
| 103 |
-
|
| 104 |
-
# Show results or message only after button click
|
| 105 |
-
submit_button.click(toggle_output, inputs=[output_area, output_message], outputs=[output_area, output_message])
|
| 106 |
|
| 107 |
-
demo.launch()
|
| 108 |
|
| 109 |
# Run the app
|
| 110 |
run_app()
|
|
|
|
| 48 |
def groq_process_data(content):
|
| 49 |
return content.head() # Returning first 5 rows for illustration
|
| 50 |
|
| 51 |
+
# Gradio interface function for new result page
|
| 52 |
+
def result_page(content):
|
| 53 |
+
return content
|
| 54 |
+
|
| 55 |
# Gradio interface function
|
| 56 |
def gradio_interface(selected_class, selected_subject, selected_chapter, content_type):
|
| 57 |
content = get_content(selected_class, selected_subject, selected_chapter, content_type)
|
| 58 |
|
| 59 |
if content is not None and not content.empty:
|
| 60 |
processed_content = groq_process_data(content)
|
| 61 |
+
# Launching a new page with the result
|
| 62 |
+
gr.Interface(fn=result_page, inputs=gr.Dataframe(value=processed_content), outputs=gr.Dataframe()).launch()
|
| 63 |
+
return processed_content
|
| 64 |
else:
|
| 65 |
+
return "No data available currently."
|
| 66 |
|
| 67 |
# Define the Gradio interface with attractive layout and fresh output page
|
| 68 |
def run_app():
|
|
|
|
| 70 |
# Header section
|
| 71 |
gr.Markdown("# Educational Content Access App")
|
| 72 |
gr.Markdown("### Select options to view educational content.")
|
| 73 |
+
|
| 74 |
+
# Input section: Using card-style layout for a neat appearance
|
| 75 |
with gr.Row():
|
| 76 |
with gr.Column(scale=1):
|
| 77 |
selected_class = gr.Dropdown(label="Select Class", choices=["Class 9", "Class 10", "Class 11", "Class 12"], interactive=True)
|
|
|
|
| 82 |
# Submit Button to generate content
|
| 83 |
submit_button = gr.Button("Show Content", variant="primary")
|
| 84 |
|
| 85 |
+
# Connecting the button to the output, results will be shown on a new page
|
| 86 |
+
submit_button.click(gradio_interface, inputs=[selected_class, selected_subject, selected_chapter, content_type], outputs=[])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 87 |
|
| 88 |
+
demo.launch(share=True) # Launch the app with the share parameter to open it on a new page
|
| 89 |
|
| 90 |
# Run the app
|
| 91 |
run_app()
|