Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lessonarc/README.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Create a virtual environment and install the packages.
pip install -r requirements.txt
72 changes: 72 additions & 0 deletions lessonarc/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
from flask import Flask, render_template, request
import openai
import requests

# Initialize the Flask app
app = Flask(__name__)

# Set your OpenAI API key
openai.api_key = "" # Replace with your OpenAI API key

# Function to generate course material using OpenAI
def generate_course_material(prompt, max_tokens=200, temperature=0.7, n=1):
try:
response = openai.ChatCompletion.create(
model="gpt-3.5-turbo", # Updated to use GPT-3.5
messages=[{"role": "user", "content": prompt}],
max_tokens=max_tokens,
temperature=temperature,
n=n,
)
return [choice['message']['content'].strip() for choice in response['choices']]
except Exception as e:
return [f"Error generating content: {str(e)}"]

# Fetch an image from Unsplash based on the topic
def fetch_image(topic):
access_key = "" # Replace with your Unsplash API access key
url = f"https://api.unsplash.com/photos/random?query={topic}&client_id={access_key}"
response = requests.get(url)
if response.status_code == 200:
return response.json()['urls']['regular']
return None

# Generate quiz questions based on the topic
def generate_quiz(topic):
prompt = f"Create a quiz with 5 questions about {topic}."
return generate_course_material(prompt, max_tokens=150, temperature=0.5, n=1)

# Generate assignments based on the topic
def generate_assignment(topic):
prompt = f"Create an assignment based on {topic}."
return generate_course_material(prompt, max_tokens=150, temperature=0.5, n=1)

@app.route('/')
def index():
return render_template('index.html')

@app.route('/generate', methods=['POST'])
def generate():
topic = request.form['topic']
level = request.form['level']
max_tokens = int(request.form['max_length'])
temperature = float(request.form['temperature'])
num_return_sequences = int(request.form['num_return_sequences'])

# Prompt to generate advanced course material
prompt = f"Create a detailed course outline on {topic} for {level} level, including an introduction, chapters, and key learning points."

# Generate course material
content = generate_course_material(prompt, max_tokens, temperature, num_return_sequences)

# Fetch an image for the topic
image_url = fetch_image(topic)

# Generate quiz and assignments
quiz = generate_quiz(topic)[0]
assignment = generate_assignment(topic)[0]

return render_template('result.html', content=content, image_url=image_url, quiz=quiz, assignment=assignment, topic=topic)

if __name__ == '__main__':
app.run(debug=True)
Binary file added lessonarc/course_content.db
Binary file not shown.
3 changes: 3 additions & 0 deletions lessonarc/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Flask
openai
Flask-CORS
105 changes: 105 additions & 0 deletions lessonarc/static/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
/* Reset some default styles */
body, h1, h2, h3, p {
margin: 0;
padding: 0;
}

/* General body styles */
body {
font-family: 'Arial', sans-serif;
line-height: 1.6;
background-color: #f4f4f4;
color: #333;
}

/* Main container styles */
.container {
max-width: 900px;
margin: 20px auto;
padding: 20px;
background: #ffffff;
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
border-radius: 8px;
}

/* Form styles */
form {
display: flex;
flex-direction: column;
}

/* Input styles */
input[type="text"],
input[type="number"],
select {
padding: 12px;
margin-bottom: 15px;
border: 1px solid #ccc;
border-radius: 4px;
}

/* Button styles */
button {
padding: 12px 20px;
background-color: #007bff;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
transition: background-color 0.3s;
}

button:hover {
background-color: #0056b3;
}

/* Result section styles */
.result-section {
margin-top: 20px;
}

.variation {
margin-bottom: 20px;
padding: 15px;
border: 1px solid #ddd;
border-radius: 4px;
background-color: #f9f9f9;
}

.result-image {
max-width: 100%;
height: auto;
border-radius: 4px;
}

/* Quiz and assignment section styles */
.quiz, .assignment {
background-color: #e9ecef;
padding: 15px;
margin-top: 20px;
border-left: 4px solid #007bff;
}

/* Footer styles */
footer {
text-align: center;
margin-top: 40px;
color: #777;
}

/* Responsive adjustments */
@media (max-width: 600px) {
.container {
padding: 15px;
}

input[type="text"],
input[type="number"],
select {
margin-bottom: 10px;
}

button {
padding: 10px 15px;
}
}
32 changes: 32 additions & 0 deletions lessonarc/templates/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Course Material Generator</title>
<link rel="stylesheet" href="{{ url_for('static', filename='style.css') }}">
</head>
<body>
<div class="container">
<h1>Generate Course Material</h1>
<form action="/generate" method="post">
<label for="topic">Course Topic:</label>
<input type="text" id="topic" name="topic" required>

<label for="level">Difficulty Level:</label>
<input type="text" id="level" name="level" required>

<label for="max_length">Maximum Tokens:</label>
<input type="number" id="max_length" name="max_length" value="200" required>

<label for="temperature">Creativity (Temperature):</label>
<input type="number" id="temperature" name="temperature" step="0.1" value="0.7" required>

<label for="num_return_sequences">Number of Variations:</label>
<input type="number" id="num_return_sequences" name="num_return_sequences" value="1" required>

<button type="submit">Generate Course Material</button>
</form>
</div>
</body>
</html>
39 changes: 39 additions & 0 deletions lessonarc/templates/result.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Generated Course Material</title>
<link rel="stylesheet" href="{{ url_for('static', filename='style.css') }}">
</head>
<body>
<div class="container">
<h1>Generated Course Material for "{{ topic }}"</h1>
<div class="result-section">
{% for text in content %}
<div class="variation">
<h2>Variation {{ loop.index }}:</h2>
<p>{{ text }}</p>
</div>
{% endfor %}
</div>

{% if image_url %}
<h2>Related Image:</h2>
<img src="{{ image_url }}" alt="Related to {{ topic }}" class="result-image">
{% endif %}

<div class="quiz">
<h2>Quiz:</h2>
<p>{{ quiz }}</p>
</div>

<div class="assignment">
<h2>Assignment:</h2>
<p>{{ assignment }}</p>
</div>

<a href="/"><button>Generate More</button></a>
</div>
</body>
</html>