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