CGF-School_Kit / lesson_plan.py
rahul-appu's picture
init Commit
e3562c3 verified
import requests
import gradio as gr
from helper import generate_access_token
def generate_lesson_plan(board, grade, subject, topics, duration, learning_outcomes, curriculum_framework):
data = {
"board": board,
"curriculum_framework": curriculum_framework,
"duration": duration,
"grade": grade,
"institution_id": "inst789",
"learning_outcomes": learning_outcomes.split(", "),
"subject": subject,
"teacher_id": "teacher456",
"topics": topics.split(", ")
}
access_token = generate_access_token()
if access_token is None:
return {"Error": "Failed to generate access token"}
response = requests.post("http://20.193.151.200:8080/v1/k12/generate/lesson-plan",
headers={
"accept": "application/json",
"content-type": "application/json",
"Authorization": f"{access_token}"},
json=data)
if(str(response.status_code)[0] != '2'):
return {"Error": f"{response.status_code}"}
return response.json()
def get_lesson_plan(request_id):
access_token = generate_access_token()
if access_token is None:
return {"Error": "Failed to generate access token"}
url = f"http://20.193.151.200:8080/v1/k12/generate/lesson-plan/{request_id}"
headers = {"accept": "application/json",
"Authorization": access_token}
response = requests.get(url, headers=headers)
if response.status_code == 200:
return response.json()
else:
return {"Error" : f"{response.status_code}"}
def post_interface():
with gr.Blocks() as post_page:
board = gr.Textbox(label="Board", value="NCERT")
grade = gr.Textbox(label="Grade", value="8")
subject = gr.Textbox(label="Subject", value="Science")
topics = gr.Textbox(label="Topics (comma-separated)", value="Plant and Animal Cells, Reproduction in Humans and Animals")
duration = gr.Number(label="Duration (minutes)", value=45)
learning_outcomes = gr.Textbox(label="Learning Outcomes (comma-separated)")
curriculum_framework = gr.Textbox(label="Curriculum Framework", value="ncf2023")
output = gr.JSON(label="Lesson Plan ID")
submit_button = gr.Button("Invoke Request")
submit_button.click(
generate_lesson_plan,
inputs=[board, grade, subject, topics, duration, learning_outcomes, curriculum_framework],
outputs=output
)
def get_interface():
with gr.Blocks() as get_page:
interface = gr.Interface(
fn=get_lesson_plan,
inputs=gr.Textbox(label="Enter Request ID"),
outputs="json",
)
return get_page
def lesson_plan():
gr.Markdown("# Lesson Plan Generation")
with gr.Blocks() as lesson_plan:
with gr.Tabs():
with gr.TabItem("POST"):
post_interface()
with gr.TabItem("GET"):
get_interface()
return lesson_plan