ai code snippets 2
satya - 1/24/2024, 10:43:53 PM
How do I load spacy stuff
pip install spacy
python -m spacy download en_core_web_sm
# Then
import spacy
# Load the installed model
nlp = spacy.load("en_core_web_sm")
# Now you can process text using the model
doc = nlp("This is a sentence.")
satya - 1/24/2024, 10:46:49 PM
Vscode frustration
- venv sucks as pylance is not recognizing new modules although program works
- Remved venv and pycache
- Created a new work space with no venv
- For some reason vscode insists that I have a venv and disables the entire work space from running a command line terminal
- Started all over and have to explicitly "create" a work space instead of a folder to get the "basic" python work.
- No venv at this point
- Until I figure out pylance this is quite useless
satya - 1/25/2024, 8:39:57 AM
Workspaces, venv, and folders
- Each folder is common to have its own .venv
- Each folder corresponds to each project
- Vscode should allow where to place the .venv
- Shared virtual environments are possible but within the workspace
- within the workspace means, any root folder in that work space
- It is a common practice to have the workspace file outside of the root folders of that workspace
satya - 1/25/2024, 8:42:11 AM
How to debug the Pylance mess
Basic settings
*******************
"python.analysis.typeCheckingMode": "basic"
"python.analysis.diagnosticSeverityOverrides": {
"reportMissingImports": "error",
"reportMissingModuleSource": "error",
// other overrides
}
python: language server
*************************
Use "default" [or pylance]
In settings .json
*************************
{
"python.analysis.extraPaths": [
"/path/to/extra/library1",
"/path/to/extra/library2"
]
}
More on the paths
***************************
{
"python.analysis.extraPaths": [
"./external_libs/lib1",
"/absolute/path/to/lib2"
]
}
The "." is a root of the work space
Likely the ./.venv/libs/lib1
root folder of the project
Project/Folder level settings
**************************
.vscode/settings.json
satya - 1/25/2024, 5:53:39 PM
Here is what happens with Streamlit
- Just a python lib in your command line apps
- pip install it, just another lib (of course like all other python stuff the dependencies galore)
- You are ready to go
- If you run streamlit on a command line it creates a webapp on your local box
- It uses the python file you specify as its home page
- That .py file has write statements in it like hello world
- that is your first webapp!
satya - 1/25/2024, 5:55:26 PM
How long it took me: 1 hour for a basic page
- Went to their web page
- Read getting started
- wrote what I want in English
- Gave it to chatgpt
- I copied the code
- A web form with its output back to the page is the requirements
- About an hour
satya - 1/25/2024, 5:57:03 PM
Here is English instructions
Filename: streamlit-ui-requirements.txt
A file to guide ChatGPT based development
**********************************
Requirement 1: for ChatGPT: Create a webpage with a from submission
**********************************
What I want:
1. Create a function
2. it should prompt the user on command line with a prompt
3. Gather the prompt from user
4. If the prompt is empty exit the program
5. if the prompt is "q" or "quit" exactly exit the program
6. call a function to process the prompt. Call this function "processPrompt"
7. Put all this in a while loop
8. Call the function "executePromptLoop"
Assume:
1. To write code modularly
satya - 1/25/2024, 5:59:44 PM
Here is the code for that web page
import streamlit as st
#
#**************************************************
# Key elements
# 1. A form with a submit
# 2. Process text input
# 3. Write back what is entered so far
# 4. Rememebers with each web refresh the state
#**************************************************
#
def writeIntro():
# Streamlit page layout
st.title("Demo page")
st.write("hello there")
st.write("hello there")
st.write("hello there")
def initialize_state():
writeIntro()
"""Initialize the state variable."""
if 'totalResponseText' not in st.session_state:
st.session_state.totalResponseText = []
def writeOutput():
# Display the accumulated text
st.write("Accumulated Text:")
for line in st.session_state.totalResponseText:
st.write(line)
def process_input(input_text):
"""Append the input text to the totalResponseText state variable."""
st.session_state.totalResponseText.append(input_text)
def main():
"""Main function to render the Streamlit page."""
initialize_state()
# Create a form
with st.form(key='input_form'):
text_input = st.text_input("Enter your text")
submit_button = st.form_submit_button("Submit")
# Process the form submission
if submit_button and text_input:
process_input(text_input)
writeOutput()
#Kick it off
main()
satya - 1/27/2024, 11:47:05 AM
where is nltk shakespeare corpus documented?
where is nltk shakespeare corpus documented?
satya - 1/27/2024, 12:56:14 PM
Github, Martin Gorner, SOnnets text
satya - 1/27/2024, 1:08:23 PM
where is to download the shakespeare sonnets.txt file?
where is to download the shakespeare sonnets.txt file?
Search for: where is to download the shakespeare sonnets.txt file?