Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -36,7 +36,6 @@ 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")
|
42 |
|
@@ -211,85 +210,105 @@ def link_button_with_emoji(url, title, emoji_summary):
|
|
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 |
-
"
|
225 |
-
"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
-
|
245 |
-
def display_python_parts():
|
246 |
st.title("Python Interactive Learning Platform")
|
247 |
-
|
248 |
-
for part,
|
249 |
-
with st.expander(f"{emoji} {part} - {
|
250 |
-
# Interactive examples
|
251 |
if st.button(f"Show Example for {part}", key=f"example_{part}"):
|
252 |
-
example =
|
253 |
example_placeholders[part] = example
|
254 |
st.code(example_placeholders[part], language="python")
|
255 |
-
response = chat_with_model('
|
|
|
|
|
|
|
256 |
|
257 |
-
# Quizzes
|
258 |
if st.button(f"Take Quiz on {part}", key=f"quiz_{part}"):
|
259 |
-
quiz =
|
260 |
-
response = chat_with_model(quiz, part)
|
|
|
|
|
|
|
261 |
|
262 |
-
|
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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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:
|
@@ -708,4 +727,4 @@ with st.sidebar:
|
|
708 |
st.session_state.conversation = get_chain(vectorstore)
|
709 |
st.markdown('# AI Search Index of Length:' + length + ' Created.') # add timing
|
710 |
filename = generate_filename(raw, 'txt')
|
711 |
-
create_file(filename, raw, '', should_save)
|
|
|
36 |
from io import BytesIO
|
37 |
from contextlib import redirect_stdout
|
38 |
|
|
|
39 |
# set page config once
|
40 |
st.set_page_config(page_title="Python AI Pair Programmer", layout="wide")
|
41 |
|
|
|
210 |
random_emoji = random.choice(emojis)
|
211 |
st.markdown(f"[{random_emoji} {emoji_summary} - {title}]({url})")
|
212 |
|
|
|
|
|
213 |
python_parts = {
|
214 |
+
"Syntax": {"emoji": "βοΈ", "details": "Variables, Comments, Printing"},
|
215 |
+
"Data Types": {"emoji": "π", "details": "Numbers, Strings, Lists, Tuples, Sets, Dictionaries"},
|
216 |
+
"Control Structures": {"emoji": "π", "details": "If, Elif, Else, Loops, Break, Continue"},
|
217 |
+
"Functions": {"emoji": "π§", "details": "Defining, Calling, Parameters, Return Values"},
|
218 |
+
"Classes": {"emoji": "ποΈ", "details": "Creating, Inheritance, Methods, Properties"},
|
219 |
+
"API Interaction": {"emoji": "π", "details": "Requests, JSON Parsing, HTTP Methods"},
|
220 |
+
"Data Visualization Libraries1": {"emoji": "π", "details": "matplotlib"},
|
221 |
+
"Data Visualization Libraries2": {"emoji": "π", "details": "seaborn"},
|
222 |
+
"Data Visualization Libraries3": {"emoji": "π", "details": "plotly"},
|
223 |
+
"Data Visualization Libraries4": {"emoji": "π", "details": "altair"},
|
224 |
+
"Data Visualization Libraries5": {"emoji": "π", "details": "bokeh"},
|
225 |
+
"Data Visualization Libraries6": {"emoji": "π", "details": "pydeck"},
|
226 |
+
"Data Visualization Libraries7": {"emoji": "π", "details": "holoviews"},
|
227 |
+
"Data Visualization Libraries8": {"emoji": "π", "details": "plotnine"},
|
228 |
+
"Data Visualization Libraries9": {"emoji": "π", "details": "graphviz"},
|
229 |
+
"Error Handling": {"emoji": "β οΈ", "details": "Try, Except, Finally, Raising"},
|
230 |
+
"Scientific & Data Analysis Libraries": {"emoji": "π§ͺ", "details": "Numpy, Pandas, Scikit-Learn, TensorFlow, SciPy, Pillow"},
|
231 |
+
"Advanced Concepts": {"emoji": "π§ ", "details": "Decorators, Generators, Context Managers, Metaclasses, Asynchronous Programming"},
|
232 |
+
"Web & Network Libraries": {"emoji": "πΈοΈ", "details": "Flask, Django, Requests, BeautifulSoup, HTTPX, Asyncio"},
|
233 |
+
"Streamlit & Extensions1": {"emoji": "π‘", "details": "Streamlit"},
|
234 |
+
"Streamlit & Extensions2": {"emoji": "π‘", "details": "Streamlit-AgGrid"},
|
235 |
+
"Streamlit & Extensions3": {"emoji": "π‘", "details": "Streamlit-Folium"},
|
236 |
+
"Streamlit & Extensions4": {"emoji": "π‘", "details": "Streamlit-Pandas-Profiling"},
|
237 |
+
"Streamlit & Extensions5": {"emoji": "π‘", "details": "Streamlit-Vega-Lite, Gradio"},
|
238 |
+
"Gradio": {"emoji": "π‘", "details": "gradio"},
|
239 |
+
"File Handling & Serialization": {"emoji": "π", "details": "PyPDF2, Pytz, Json, Base64, Zipfile, Random, Glob, IO"},
|
240 |
+
"Machine Learning & AI": {"emoji": "π€", "details": "OpenAI, LangChain, HuggingFace"},
|
241 |
+
"Text & Data Extraction": {"emoji": "π", "details": "TikToken, Textract, SQLAlchemy, Pillow"},
|
242 |
+
"XML & Collections Libraries": {"emoji": "π", "details": "XML, Collections"},
|
243 |
+
"Top PyPI Libraries1": {"emoji": "π", "details": "Requests, Pillow, SQLAlchemy, Flask, Django, SciPy, Beautiful Soup, PyTest, PyGame, Twisted"},
|
244 |
+
"Top PyPI Libraries2": {"emoji": "π", "details": "numpy, pandas, matplotlib, requests, beautifulsoup4"},
|
245 |
+
"Top PyPI Libraries3": {"emoji": "π", "details": "langchain, openai, PyPDF2, pytz"},
|
246 |
+
"Top PyPI Libraries4": {"emoji": "π", "details": "streamlit, audio_recorder_streamlit, gradio"},
|
247 |
+
"Top PyPI Libraries5": {"emoji": "π", "details": "tiktoken, textract, glob, io"},
|
248 |
+
"Top PyPI Libraries6": {"emoji": "π", "details": "matplotlib, seaborn, plotly, altair, bokeh, pydeck"},
|
249 |
+
"Top PyPI Libraries7": {"emoji": "π", "details": "streamlit, streamlit-aggrid, streamlit-folium, streamlit-pandas-profiling, streamlit-vega-lite"},
|
250 |
+
"Top PyPI Libraries8": {"emoji": "π", "details": "holoviews, plotnine, graphviz"},
|
251 |
+
"Top PyPI Libraries9": {"emoji": "π", "details": "json, base64, zipfile, random"},
|
252 |
+
"Top PyPI Libraries10": {"emoji": "π", "details": "httpx, asyncio, xml, collections, huggingface "}
|
253 |
}
|
254 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
255 |
|
|
|
256 |
response_placeholders = {}
|
257 |
example_placeholders = {}
|
258 |
|
259 |
+
def display_python_parts_old2():
|
|
|
260 |
st.title("Python Interactive Learning Platform")
|
261 |
+
|
262 |
+
for part, content in python_parts.items():
|
263 |
+
with st.expander(f"{content['emoji']} {part} - {content['details']}", expanded=False):
|
|
|
264 |
if st.button(f"Show Example for {part}", key=f"example_{part}"):
|
265 |
+
example = "Write short python script examples with mock data in python list dictionary for inputs for " + part
|
266 |
example_placeholders[part] = example
|
267 |
st.code(example_placeholders[part], language="python")
|
268 |
+
response = chat_with_model(f'Write python script with short code examples for: {content["details"]}', part)
|
269 |
+
response_placeholders[part] = response
|
270 |
+
st.write(f"#### {content['emoji']} {part} Example")
|
271 |
+
st.code(response_placeholders[part], language="python")
|
272 |
|
|
|
273 |
if st.button(f"Take Quiz on {part}", key=f"quiz_{part}"):
|
274 |
+
quiz = "Write Python script quiz examples with mock static data inputs for " + part
|
275 |
+
response = chat_with_model(f'Write python code blocks for quiz program: {quiz}', part)
|
276 |
+
response_placeholders[part] = response
|
277 |
+
st.write(f"#### {content['emoji']} {part} Quiz")
|
278 |
+
st.code(response_placeholders[part], language="python")
|
279 |
|
280 |
+
prompt = f"Write python script with a few advanced coding examples using mock data input for {content['details']}"
|
|
|
281 |
if st.button(f"Explore {part}", key=part):
|
282 |
response = chat_with_model(prompt, part)
|
283 |
response_placeholders[part] = response
|
284 |
+
st.write(f"#### {content['emoji']} {part} Details")
|
285 |
+
st.code(response_placeholders[part], language="python")
|
286 |
+
|
287 |
|
288 |
+
def display_python_parts():
|
289 |
+
st.title("Python Interactive Learning Platform")
|
290 |
+
for part, content in python_parts.items():
|
291 |
+
with st.expander(f"{content['emoji']} {part} - {content['details']}", expanded=False):
|
292 |
+
if st.button(f"Show Example for {part}", key=f"example_{part}"):
|
293 |
+
example = "Python script example with mock example inputs for " + part
|
294 |
+
example_placeholders[part] = example
|
295 |
+
st.code(example_placeholders[part], language="python")
|
296 |
+
response = chat_with_model('Create detailed advanced python script code examples for:' + example_placeholders[part], part)
|
297 |
+
if st.button(f"Take Quiz on {part}", key=f"quiz_{part}"):
|
298 |
+
quiz = "Python script quiz example with mock example inputs for " + part
|
299 |
+
response = chat_with_model(quiz, part)
|
300 |
+
prompt = f"Learn about advanced coding examples using mock example inputs for {content['details']}"
|
301 |
+
if st.button(f"Explore {part}", key=part):
|
302 |
+
response = chat_with_model(prompt, part)
|
303 |
+
response_placeholders[part] = response
|
304 |
if part in response_placeholders:
|
305 |
st.markdown(f"**Response:** {response_placeholders[part]}")
|
306 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
307 |
def add_paper_buttons_and_links():
|
|
|
308 |
page = st.sidebar.radio("Choose a page:", ["Python Pair Programmer"])
|
309 |
if page == "Python Pair Programmer":
|
|
|
310 |
display_python_parts()
|
311 |
|
|
|
|
|
|
|
312 |
col1, col2, col3, col4 = st.columns(4)
|
313 |
|
314 |
with col1:
|
|
|
727 |
st.session_state.conversation = get_chain(vectorstore)
|
728 |
st.markdown('# AI Search Index of Length:' + length + ' Created.') # add timing
|
729 |
filename = generate_filename(raw, 'txt')
|
730 |
+
create_file(filename, raw, '', should_save)
|