Spaces:
Runtime error
Runtime error
Update app.py
Browse files210 unmodified lines211212213214215214217218219220221222223224225226227228229230231232233234235236237215216217218219220221222223224225226227240228229230244231232247248249233234250235252236237238239256257240259241242261262263243244245246267268247248249272273274275276277278279280281282250284251252287253254290291292255256257210 unmodified lines random_emoji = random.choice(emojis) st.markdown(f"[{random_emoji} {emoji_summary} - {title}]({url})")
# Python parts and their corresponding emojis, with expanded detailspython_parts = { "Syntax": "βοΈ", "Data Types": "π", "Control Structures": "π", "Functions": "π§", "Classes": "ποΈ", "API Interaction": "π", "Data Visualization": "π", "Error Handling": "β οΈ", "Libraries": "π"}
python_parts_extended = { "Syntax": "βοΈ (Variables, Comments, Printing)", "Data Types": "π (Numbers, Strings, Lists, Tuples, Sets, Dictionaries)", "Control Structures": "π (If, Elif, Else, Loops, Break, Continue)", "Functions": "π§ (Defining, Calling, Parameters, Return Values)", "Classes": "ποΈ (Creating, Inheritance, Methods, Properties)", "API Interaction": "π (Requests, JSON Parsing, HTTP Methods)", "Data Visualization": "π (Matplotlib, Seaborn, Plotly)", "Error Handling": "β οΈ (Try, Except, Finally, Raising)", "Libraries": "π (Numpy, Pandas, Scikit-Learn, TensorFlow)" "Syntax": {"emoji": "βοΈ", "details": "Variables, Comments, Printing"}, "Data Types": {"emoji": "π", "details": "Numbers, Strings, Lists, Tuples, Sets, Dictionaries"}, "Control Structures": {"emoji": "π", "details": "If, Elif, Else, Loops, Break, Continue"}, "Functions": {"emoji": "π§", "details": "Defining, Calling, Parameters, Return Values"}, "Classes": {"emoji": "ποΈ", "details": "Creating, Inheritance, Methods, Properties"}, "API Interaction": {"emoji": "π", "details": "Requests, JSON Parsing, HTTP Methods"}, "Data Visualization": {"emoji": "π", "details": "Matplotlib, Seaborn, Plotly"}, "Error Handling": {"emoji": "β οΈ", "details": "Try, Except, Finally, Raising"}, "Libraries": {"emoji": "π", "details": "Numpy, Pandas, Scikit-Learn, TensorFlow"}, "Advanced Concepts": {"emoji": "π§ ", "details": "Decorators, Generators, Context Managers, Metaclasses, Asynchronous Programming"}, "Top PyPI Libraries": {"emoji": "π", "details": "Requests, Pillow, SQLAlchemy, Flask, Django, SciPy, Beautiful Soup, PyTest, PyGame, Twisted"}}
# Placeholder for chat responses and interactive examplesresponse_placeholders = {}example_placeholders = {}
# Function to display Python concepts with expanders, examples, and quizzesdef display_python_parts(): st.title("Python Interactive Learning Platform")
for part, emoji in python_parts.items(): with st.expander(f"{emoji} {part} - {python_parts_extended[part]}", expanded=False): for part, content in python_parts.items(): with st.expander(f"{content['emoji']} {part} - {content['details']}", expanded=False): # Interactive examples if st.button(f"Show Example for {part}", key=f"example_{part}"): example = generate_example(part) example = "Python script example with mock example inputs for " + part example_placeholders[part] = example st.code(example_placeholders[part], language="python") response = chat_with_model('Create a STEM related 3 to 5 line python code example with output for:' + example_placeholders[part], part)
# Quizzes if st.button(f"Take Quiz on {part}", key=f"quiz_{part}"): quiz = generate_quiz(part) quiz = "Python script quiz example with mock example inputs for " + part response = chat_with_model(quiz, part)
# Chat responses prompt = f"Learn about {python_parts_extended[part]}" prompt = f"Learn about advanced coding examples using mock example inputs for {content['details']}" if st.button(f"Explore {part}", key=part): response = chat_with_model(prompt, part) response_placeholders[part] = response
# Display the chat response if available if part in response_placeholders: st.markdown(f"**Response:** {response_placeholders[part]}")
def generate_example(part): # This function will return a relevant Python example based on the selected part # Examples could be pre-defined or dynamically generated return "Python example for " + part
def generate_quiz(part): # This function will create a simple quiz related to the Python part # Quizzes could be multiple-choice questions, true/false, etc. return "Python script quiz example for " + part # Define function to add paper buttons and linksdef add_paper_buttons_and_links(): # Python Pair Programmer page = st.sidebar.radio("Choose a page:", ["Python Pair Programmer"]) if page == "Python Pair Programmer": # Display Python concepts and interactive sections display_python_parts()
col1, col2, col3, col4 = st.columns(4)
with col1:app.py+16-54