shaheerawan3's picture
Update app.py
bd52c26 verified
# app.py
import streamlit as st
from model import CodeTeachingAssistant
import time
@st.cache_resource
def init_model():
"""Initialize model with caching to prevent reloading."""
with st.spinner("Loading AI model (this will be faster on subsequent runs)..."):
model = CodeTeachingAssistant()
return model
def main():
st.title("πŸš€ Advanced AI Programming Teacher")
st.write("Programming assistant with real-time analysis")
# Initialize model with caching
try:
model = init_model()
except Exception as e:
st.error(f"Error loading model: {str(e)}")
return
# Simplified interface with fewer tabs
tab1, tab2 = st.tabs([
"πŸ’» Code Analysis",
"🎯 Learning Path"
])
with tab1:
st.header("Code Analysis")
code = st.text_area(
"Enter your code for analysis:",
height=200,
help="Paste your code here for analysis"
)
if st.button("Analyze Code", type="primary"):
if code:
with st.spinner("Analyzing code..."):
analysis = model.analyze_code_quality(code)
if analysis:
st.metric("Complexity Score", f"{analysis.complexity:.2f}")
with st.expander("View Suggestions"):
for suggestion in analysis.suggestions:
st.write(f"β€’ {suggestion}")
with st.expander("View Security Issues"):
for issue in analysis.security_issues:
st.warning(issue)
with tab2:
st.header("Learning Path")
user_level = st.select_slider(
"Select your expertise level:",
options=["Beginner", "Intermediate", "Advanced"]
)
if code:
with st.spinner("Generating learning path..."):
learning_path = model.learning_path_generator(code, user_level)
st.write(f"**Current Level:** {learning_path['current_level']}")
with st.expander("View Learning Path"):
st.write("**Concepts to Master:**")
for concept in learning_path['concepts_to_learn']:
st.write(f"β€’ {concept}")
st.write("**Estimated Timeline:**")
st.write(learning_path['estimated_timeline'])
if __name__ == "__main__":
main()