Spaces:
Runtime error
Runtime error
Update app.py
Browse files210 unmodified lines211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295210 unmodified linesrandom_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)"}# 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):# Interactive examplesif st.button(f"Show Example for {part}", key=f"example_{part}"):example = generate_example(part)example_placeholders[part] = examplest.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)# Quizzesif st.button(f"Take Quiz on {part}", key=f"quiz_{part}"):quiz = generate_quiz(part)response = chat_with_model(quiz, part)# Chat responsesprompt = f"Learn about {python_parts_extended[part]}"if st.button(f"Explore {part}", key=part):response = chat_with_model(prompt, part)response_placeholders[part] = response# Display the chat response if availableif 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 generatedreturn "Python example for " + partdef 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 Programmerpage = st.sidebar.radio("Choose a page:", ["Python Pair Programmer"])if page == "Python Pair Programmer":# Display Python concepts and interactive sectionsdisplay_python_parts()col1, col2, col3, col4 = st.columns(4)with col1:210 unmodified lines211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257210 unmodified linesrandom_emoji = random.choice(emojis)st.markdown(f"[{random_emoji} {emoji_summary} - {title}]({url})")python_parts = {"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"}}response_placeholders = {}example_placeholders = {}def display_python_parts():st.title("Python Interactive Learning Platform")for part, content in python_parts.items():with st.expander(f"{content['emoji']} {part} - {content['details']}", expanded=False):if st.button(f"Show Example for {part}", key=f"example_{part}"):example = "Python script example with mock example inputs for " + partexample_placeholders[part] = examplest.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)if st.button(f"Take Quiz on {part}", key=f"quiz_{part}"):quiz = "Python script quiz example with mock example inputs for " + partresponse = chat_with_model(quiz, 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] = responseif part in response_placeholders:st.markdown(f"**Response:** {response_placeholders[part]}")def add_paper_buttons_and_links():page = st.sidebar.radio("Choose a page:", ["Python Pair Programmer"])if page == "Python Pair Programmer":display_python_parts()col1, col2, col3, col4 = st.columns(4)with col1:
app.py+16-54