awacke1 commited on
Commit
a74e86f
Β·
1 Parent(s): 622fa35

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +74 -55
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
- "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:
@@ -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)