Spaces:
Build error

ATG / app.py
VAH6002's picture
Create app.py
be57018 verified
Raw History Blame Contribute Delete
4.06 kB
import streamlit as st
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from sklearn.cluster import KMeans
import google.generativeai as genai
# Set up Google Gemini API key (replace with your actual key)
GOOGLE_API_KEY = "AIzaSyAAm3ULEyur-Yv8zQnPt7yblFa4fklB0T0"
genai.configure(api_key=GOOGLE_API_KEY)
# Initialize the model
model = genai.GenerativeModel('gemini-pro')
# Simulated student data
students_data = pd.DataFrame({
'student_id': range(1, 31),
'math_score': np.random.randint(50, 100, 30),
'reading_score': np.random.randint(50, 100, 30),
'writing_score': np.random.randint(50, 100, 30),
'learning_style': np.random.choice(['visual', 'auditory', 'kinesthetic'], 30)
})
def generate_lesson_plan(topic, learning_style):
prompt = f"Create a lesson plan for teaching {topic} to {learning_style} learners. Include activities and explanations suitable for this learning style."
response = model.generate_content(prompt)
return response.text
def generate_adaptive_content(topic, difficulty):
prompt = f"Generate a {difficulty} level explanation of {topic} suitable for a student who needs additional support."
response = model.generate_content(prompt)
return response.text
def cluster_students(data):
X = data[['math_score', 'reading_score', 'writing_score']]
kmeans = KMeans(n_clusters=3, random_state=42)
data['cluster'] = kmeans.fit_predict(X)
return data
st.title("Nasir's AI-Powered Personalized Learning Assistant")
# Sidebar for teacher input
st.sidebar.header("Teacher Dashboard")
topic = st.sidebar.text_input("Enter the topic you want to teach:")
generate_plan = st.sidebar.button("Generate Lesson Plans")
# Main content area
if generate_plan and topic:
st.header(f"Personalized Lesson Plans for {topic}")
for style in ['visual', 'auditory', 'kinesthetic']:
st.subheader(f"Lesson Plan for {style.capitalize()} Learners")
lesson_plan = generate_lesson_plan(topic, style)
st.write(lesson_plan)
# # Student progress tracking
# st.header("Student Progress Tracking")
# clustered_data = cluster_students(students_data)
# fig, ax = plt.subplots(figsize=(10, 6))
# scatter = ax.scatter(clustered_data['math_score'], clustered_data['reading_score'],
# c=clustered_data['cluster'], cmap='viridis')
# ax.set_xlabel('Math Score')
# ax.set_ylabel('Reading Score')
# ax.set_title('Student Clusters based on Performance')
# st.pyplot(fig)
st.header("Student Progress Tracking")
clustered_data = cluster_students(students_data)
fig, ax = plt.subplots(figsize=(10, 6))
scatter = ax.scatter(clustered_data['math_score'], clustered_data['reading_score'],
c=clustered_data['cluster'], cmap='viridis')
ax.set_xlabel('Math Score')
ax.set_ylabel('Reading Score')
ax.set_title('Student Clusters based on Performance')
# Display student IDs on the plot
for i, row in clustered_data.iterrows():
ax.text(row['math_score'], row['reading_score'], str(row['student_id']), fontsize=8, ha='right')
st.pyplot(fig)
# Adaptive learning content generation
st.header("Adaptive Learning Content Generation")
student_id = st.number_input("Enter student ID for personalized content:", min_value=1, max_value=30, value=1)
student = clustered_data[clustered_data['student_id'] == student_id].iloc[0]
difficulty = "easy" if student['cluster'] == 0 else "medium" if student['cluster'] == 1 else "challenging"
if topic:
st.subheader(f"Personalized Content for Student {student_id}")
adaptive_content = generate_adaptive_content(topic, difficulty)
st.write(adaptive_content)
st.sidebar.markdown("---")
st.sidebar.subheader("How this AI Assistant Helps:")
st.sidebar.markdown("""
1. Generates personalized lesson plans for different learning styles
2. Tracks student progress using clustering algorithms
3. Creates adaptive learning content based on student performance
4. Helps teachers manage larger class sizes efficiently
5. Provides tailored support for students with diverse educational needs
""")