Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -35,16 +35,7 @@ from langchain.chains import ConversationalRetrievalChain
|
|
35 |
from templates import css, bot_template, user_template
|
36 |
from io import BytesIO
|
37 |
from contextlib import redirect_stdout
|
38 |
-
|
39 |
-
import seaborn
|
40 |
-
import plotly
|
41 |
-
import vega_datasets
|
42 |
-
import bokeh
|
43 |
-
import holoviews
|
44 |
-
import plotnine
|
45 |
-
import graphviz
|
46 |
-
import tensorflow
|
47 |
-
import torch
|
48 |
|
49 |
# set page config once
|
50 |
st.set_page_config(page_title="Python AI Pair Programmer", layout="wide")
|
@@ -220,105 +211,85 @@ def link_button_with_emoji(url, title, emoji_summary):
|
|
220 |
random_emoji = random.choice(emojis)
|
221 |
st.markdown(f"[{random_emoji} {emoji_summary} - {title}]({url})")
|
222 |
|
|
|
|
|
223 |
python_parts = {
|
224 |
-
"Syntax":
|
225 |
-
"Data Types":
|
226 |
-
"Control Structures":
|
227 |
-
"Functions":
|
228 |
-
"Classes":
|
229 |
-
"API Interaction":
|
230 |
-
"Data Visualization
|
231 |
-
"
|
232 |
-
"
|
233 |
-
"Data Visualization Libraries4": {"emoji": "π", "details": "altair"},
|
234 |
-
"Data Visualization Libraries5": {"emoji": "π", "details": "bokeh"},
|
235 |
-
"Data Visualization Libraries6": {"emoji": "π", "details": "pydeck"},
|
236 |
-
"Data Visualization Libraries7": {"emoji": "π", "details": "holoviews"},
|
237 |
-
"Data Visualization Libraries8": {"emoji": "π", "details": "plotnine"},
|
238 |
-
"Data Visualization Libraries9": {"emoji": "π", "details": "graphviz"},
|
239 |
-
"Error Handling": {"emoji": "β οΈ", "details": "Try, Except, Finally, Raising"},
|
240 |
-
"Scientific & Data Analysis Libraries": {"emoji": "π§ͺ", "details": "Numpy, Pandas, Scikit-Learn, TensorFlow, SciPy, Pillow"},
|
241 |
-
"Advanced Concepts": {"emoji": "π§ ", "details": "Decorators, Generators, Context Managers, Metaclasses, Asynchronous Programming"},
|
242 |
-
"Web & Network Libraries": {"emoji": "πΈοΈ", "details": "Flask, Django, Requests, BeautifulSoup, HTTPX, Asyncio"},
|
243 |
-
"Streamlit & Extensions1": {"emoji": "π‘", "details": "Streamlit"},
|
244 |
-
"Streamlit & Extensions2": {"emoji": "π‘", "details": "Streamlit-AgGrid"},
|
245 |
-
"Streamlit & Extensions3": {"emoji": "π‘", "details": "Streamlit-Folium"},
|
246 |
-
"Streamlit & Extensions4": {"emoji": "π‘", "details": "Streamlit-Pandas-Profiling"},
|
247 |
-
"Streamlit & Extensions5": {"emoji": "π‘", "details": "Streamlit-Vega-Lite, Gradio"},
|
248 |
-
"Gradio": {"emoji": "π‘", "details": "gradio"},
|
249 |
-
"File Handling & Serialization": {"emoji": "π", "details": "PyPDF2, Pytz, Json, Base64, Zipfile, Random, Glob, IO"},
|
250 |
-
"Machine Learning & AI": {"emoji": "π€", "details": "OpenAI, LangChain, HuggingFace"},
|
251 |
-
"Text & Data Extraction": {"emoji": "π", "details": "TikToken, Textract, SQLAlchemy, Pillow"},
|
252 |
-
"XML & Collections Libraries": {"emoji": "π", "details": "XML, Collections"},
|
253 |
-
"Top PyPI Libraries1": {"emoji": "π", "details": "Requests, Pillow, SQLAlchemy, Flask, Django, SciPy, Beautiful Soup, PyTest, PyGame, Twisted"},
|
254 |
-
"Top PyPI Libraries2": {"emoji": "π", "details": "numpy, pandas, matplotlib, requests, beautifulsoup4"},
|
255 |
-
"Top PyPI Libraries3": {"emoji": "π", "details": "langchain, openai, PyPDF2, pytz"},
|
256 |
-
"Top PyPI Libraries4": {"emoji": "π", "details": "streamlit, audio_recorder_streamlit, gradio"},
|
257 |
-
"Top PyPI Libraries5": {"emoji": "π", "details": "tiktoken, textract, glob, io"},
|
258 |
-
"Top PyPI Libraries6": {"emoji": "π", "details": "matplotlib, seaborn, plotly, altair, bokeh, pydeck"},
|
259 |
-
"Top PyPI Libraries7": {"emoji": "π", "details": "streamlit, streamlit-aggrid, streamlit-folium, streamlit-pandas-profiling, streamlit-vega-lite"},
|
260 |
-
"Top PyPI Libraries8": {"emoji": "π", "details": "holoviews, plotnine, graphviz"},
|
261 |
-
"Top PyPI Libraries9": {"emoji": "π", "details": "json, base64, zipfile, random"},
|
262 |
-
"Top PyPI Libraries10": {"emoji": "π", "details": "httpx, asyncio, xml, collections, huggingface "}
|
263 |
}
|
264 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
265 |
|
|
|
266 |
response_placeholders = {}
|
267 |
example_placeholders = {}
|
268 |
|
269 |
-
|
|
|
270 |
st.title("Python Interactive Learning Platform")
|
271 |
-
|
272 |
-
for part,
|
273 |
-
with st.expander(f"{
|
|
|
274 |
if st.button(f"Show Example for {part}", key=f"example_{part}"):
|
275 |
-
example =
|
276 |
example_placeholders[part] = example
|
277 |
st.code(example_placeholders[part], language="python")
|
278 |
-
response = chat_with_model(
|
279 |
-
response_placeholders[part] = response
|
280 |
-
st.write(f"#### {content['emoji']} {part} Example")
|
281 |
-
st.code(response_placeholders[part], language="python")
|
282 |
|
|
|
283 |
if st.button(f"Take Quiz on {part}", key=f"quiz_{part}"):
|
284 |
-
quiz =
|
285 |
-
response = chat_with_model(
|
286 |
-
response_placeholders[part] = response
|
287 |
-
st.write(f"#### {content['emoji']} {part} Quiz")
|
288 |
-
st.code(response_placeholders[part], language="python")
|
289 |
|
290 |
-
|
|
|
291 |
if st.button(f"Explore {part}", key=part):
|
292 |
response = chat_with_model(prompt, part)
|
293 |
response_placeholders[part] = response
|
294 |
-
st.write(f"#### {content['emoji']} {part} Details")
|
295 |
-
st.code(response_placeholders[part], language="python")
|
296 |
-
|
297 |
|
298 |
-
|
299 |
-
st.title("Python Interactive Learning Platform")
|
300 |
-
for part, content in python_parts.items():
|
301 |
-
with st.expander(f"{content['emoji']} {part} - {content['details']}", expanded=False):
|
302 |
-
if st.button(f"Show Example for {part}", key=f"example_{part}"):
|
303 |
-
example = "Python script example with mock example inputs for " + part
|
304 |
-
example_placeholders[part] = example
|
305 |
-
st.code(example_placeholders[part], language="python")
|
306 |
-
response = chat_with_model('Create detailed advanced python script code examples for:' + example_placeholders[part], part)
|
307 |
-
if st.button(f"Take Quiz on {part}", key=f"quiz_{part}"):
|
308 |
-
quiz = "Python script quiz example with mock example inputs for " + part
|
309 |
-
response = chat_with_model(quiz, part)
|
310 |
-
prompt = f"Learn about advanced coding examples using mock example inputs for {content['details']}"
|
311 |
-
if st.button(f"Explore {part}", key=part):
|
312 |
-
response = chat_with_model(prompt, part)
|
313 |
-
response_placeholders[part] = response
|
314 |
if part in response_placeholders:
|
315 |
st.markdown(f"**Response:** {response_placeholders[part]}")
|
316 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
317 |
def add_paper_buttons_and_links():
|
|
|
318 |
page = st.sidebar.radio("Choose a page:", ["Python Pair Programmer"])
|
319 |
if page == "Python Pair Programmer":
|
|
|
320 |
display_python_parts()
|
321 |
|
|
|
|
|
|
|
322 |
col1, col2, col3, col4 = st.columns(4)
|
323 |
|
324 |
with col1:
|
|
|
35 |
from templates import css, bot_template, user_template
|
36 |
from io import BytesIO
|
37 |
from contextlib import redirect_stdout
|
38 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
39 |
|
40 |
# set page config once
|
41 |
st.set_page_config(page_title="Python AI Pair Programmer", layout="wide")
|
|
|
211 |
random_emoji = random.choice(emojis)
|
212 |
st.markdown(f"[{random_emoji} {emoji_summary} - {title}]({url})")
|
213 |
|
214 |
+
|
215 |
+
# Python parts and their corresponding emojis, with expanded details
|
216 |
python_parts = {
|
217 |
+
"Syntax": "βοΈ",
|
218 |
+
"Data Types": "π",
|
219 |
+
"Control Structures": "π",
|
220 |
+
"Functions": "π§",
|
221 |
+
"Classes": "ποΈ",
|
222 |
+
"API Interaction": "π",
|
223 |
+
"Data Visualization": "π",
|
224 |
+
"Error Handling": "β οΈ",
|
225 |
+
"Libraries": "π"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
226 |
}
|
227 |
|
228 |
+
python_parts_extended = {
|
229 |
+
"Syntax": "βοΈ (Variables, Comments, Printing)",
|
230 |
+
"Data Types": "π (Numbers, Strings, Lists, Tuples, Sets, Dictionaries)",
|
231 |
+
"Control Structures": "π (If, Elif, Else, Loops, Break, Continue)",
|
232 |
+
"Functions": "π§ (Defining, Calling, Parameters, Return Values)",
|
233 |
+
"Classes": "ποΈ (Creating, Inheritance, Methods, Properties)",
|
234 |
+
"API Interaction": "π (Requests, JSON Parsing, HTTP Methods)",
|
235 |
+
"Data Visualization": "π (Matplotlib, Seaborn, Plotly)",
|
236 |
+
"Error Handling": "β οΈ (Try, Except, Finally, Raising)",
|
237 |
+
"Libraries": "π (Numpy, Pandas, Scikit-Learn, TensorFlow)"
|
238 |
+
}
|
239 |
|
240 |
+
# Placeholder for chat responses and interactive examples
|
241 |
response_placeholders = {}
|
242 |
example_placeholders = {}
|
243 |
|
244 |
+
# Function to display Python concepts with expanders, examples, and quizzes
|
245 |
+
def display_python_parts():
|
246 |
st.title("Python Interactive Learning Platform")
|
247 |
+
|
248 |
+
for part, emoji in python_parts.items():
|
249 |
+
with st.expander(f"{emoji} {part} - {python_parts_extended[part]}", expanded=False):
|
250 |
+
# Interactive examples
|
251 |
if st.button(f"Show Example for {part}", key=f"example_{part}"):
|
252 |
+
example = generate_example(part)
|
253 |
example_placeholders[part] = example
|
254 |
st.code(example_placeholders[part], language="python")
|
255 |
+
response = chat_with_model('Create a STEM related 3 to 5 line python code example with output for:' + example_placeholders[part], part)
|
|
|
|
|
|
|
256 |
|
257 |
+
# Quizzes
|
258 |
if st.button(f"Take Quiz on {part}", key=f"quiz_{part}"):
|
259 |
+
quiz = generate_quiz(part)
|
260 |
+
response = chat_with_model(quiz, part)
|
|
|
|
|
|
|
261 |
|
262 |
+
# Chat responses
|
263 |
+
prompt = f"Learn about {python_parts_extended[part]}"
|
264 |
if st.button(f"Explore {part}", key=part):
|
265 |
response = chat_with_model(prompt, part)
|
266 |
response_placeholders[part] = response
|
|
|
|
|
|
|
267 |
|
268 |
+
# Display the chat response if available
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
269 |
if part in response_placeholders:
|
270 |
st.markdown(f"**Response:** {response_placeholders[part]}")
|
271 |
|
272 |
+
def generate_example(part):
|
273 |
+
# This function will return a relevant Python example based on the selected part
|
274 |
+
# Examples could be pre-defined or dynamically generated
|
275 |
+
return "Python example for " + part
|
276 |
+
|
277 |
+
def generate_quiz(part):
|
278 |
+
# This function will create a simple quiz related to the Python part
|
279 |
+
# Quizzes could be multiple-choice questions, true/false, etc.
|
280 |
+
return "Python script quiz example for " + part
|
281 |
+
|
282 |
+
# Define function to add paper buttons and links
|
283 |
def add_paper_buttons_and_links():
|
284 |
+
# Python Pair Programmer
|
285 |
page = st.sidebar.radio("Choose a page:", ["Python Pair Programmer"])
|
286 |
if page == "Python Pair Programmer":
|
287 |
+
# Display Python concepts and interactive sections
|
288 |
display_python_parts()
|
289 |
|
290 |
+
|
291 |
+
|
292 |
+
|
293 |
col1, col2, col3, col4 = st.columns(4)
|
294 |
|
295 |
with col1:
|