ai code snippets 2


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.")
  1. venv sucks as pylance is not recognizing new modules although program works
  2. Remved venv and pycache
  3. Created a new work space with no venv
  4. For some reason vscode insists that I have a venv and disables the entire work space from running a command line terminal
  5. Started all over and have to explicitly "create" a work space instead of a folder to get the "basic" python work.
  6. No venv at this point
  7. Until I figure out pylance this is quite useless
  1. Each folder is common to have its own .venv
  2. Each folder corresponds to each project
  3. Vscode should allow where to place the .venv
  4. Shared virtual environments are possible but within the workspace
  5. within the workspace means, any root folder in that work space
  6. It is a common practice to have the workspace file outside of the root folders of that workspace

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

Streamlit conversational apps

streamlit and HF

Github Sample code: Biju

Github Faisal

  1. Just a python lib in your command line apps
  2. pip install it, just another lib (of course like all other python stuff the dependencies galore)
  3. You are ready to go
  4. If you run streamlit on a command line it creates a webapp on your local box
  5. It uses the python file you specify as its home page
  6. That .py file has write statements in it like hello world
  7. that is your first webapp!
  1. Went to their web page
  2. Read getting started
  3. wrote what I want in English
  4. Gave it to chatgpt
  5. I copied the code
  6. A web form with its output back to the page is the requirements
  7. About an hour

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

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()

nltk docs

nltk corpus api

where is nltk shakespeare corpus documented?

Search for: where is nltk shakespeare corpus documented?

Closest I can find is here

wiki documentation on github

NLTK Book

Search for: NLTK Book

https://www.nltk.org/book/

Github, Martin Gorner, SOnnets text

where is to download the shakespeare sonnets.txt file?

Search for: where is to download the shakespeare sonnets.txt file?

Here is on gutenberg site