File size: 3,093 Bytes
37c96ca 23162eb 37c96ca 23162eb 37c96ca 23162eb 37c96ca |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
import streamlit as st
import openai
from reportlab.lib.pagesizes import letter
from reportlab.pdfgen import canvas
# Set OpenAI API credentials
openai.api_key = "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"
# Add custom CSS styles
st.markdown(
"""
<style>
body {
background-color: black;
color: purple;
}
/* Modify the color of the title */
.css-1fcmnw0 h1 {
color: purple;
}
/* Modify the background color of the input field */
.css-xpo4mk.st-cg {
background-color: #483d8b;
color: white;
}
/* Modify the color of the dropdown select box */
.css-2trqyj {
color: purple;
}
/* Modify the background and text color of the button */
.css-14jx6h6 {
background-color: purple;
color: white;
}
</style>
""",
unsafe_allow_html=True
)
# Set page title
st.title("A.I Lesson Plan for Teachers")
# Ask for age
age = st.number_input("Enter your age", min_value=0, max_value=100, step=1)
# Ask for subject and provide a text area
subject = st.text_area("Enter the subject")
board = st.text_area("Enter the board ex: edexcel, aqa, IB or CBSE")
# Complexity levels
complexity_levels = ["Beginner", "Intermediate", "Advanced", "Expert", "Master"]
complexity = st.selectbox("Select the complexity level", complexity_levels)
# Number of days
plan_duration = st.selectbox("Select the duration of the plan", ["1 hour", "1 week", "1 month", "3 months","6 months"])
# Generate lesson plan
if st.button("Generate Lesson Plan"):
# Define the prompt for ChatGPT
prompt = f"Generate a detailed lesson plan along with a few topic examples for teaching {subject} to {age}-year-old students. The lesson plan should have a complexity level of {complexity} and a duration of {plan_duration}.The lesson plan should follow the {board} exam board."
# Call the OpenAI API to generate the lesson plan
response = openai.Completion.create(
engine="text-davinci-003",
prompt=prompt,
max_tokens=1000,
n=1,
stop=None,
temperature=0.7
)
# Extract the generated lesson plan from the API response
lesson_plan = response.choices[0].text.strip()
# Display the generated lesson plan
st.subheader("Generated Lesson Plan")
st.write(lesson_plan)
# Create PDF file
def create_pdf():
pdf_file = "lesson_plan.pdf"
c = canvas.Canvas(pdf_file, pagesize=letter)
c.setFillColor("#000000") # Set fill color to black
c.setFont("Helvetica", 12)
c.drawString(100, 700, "Lesson Plan:")
c.setFont("Helvetica", 10)
lines = lesson_plan.split("\n")
y = 680
for line in lines:
c.drawString(100, y, line)
y -= 15
c.save()
return pdf_file
# Download button for the lesson plan in PDF format
pdf_file = create_pdf()
st.download_button(
label="Download Lesson Plan (PDF)",
data=pdf_file,
file_name="lesson_plan.pdf",
mime="application/pdf"
)
|