/what-run

Primary LanguageHTMLGNU General Public License v3.0GPL-3.0

What Run?

show web app with Rob Koch signing 'candidate' with a text box showing 'running for elected office'

The premise

There are several meanings of the word 'run'. Same with American Sign Language. We sign 'run' in different ways according to what it actually means.

The solution

I've recorded myself signing 'run' in different ways and uploaded it. GenAI will use embedding to decipher at what context does the word run means and tries to match it against a pre-defined dictionary. It'll spit out a URL that you can paste into your browser to see which sign for 'run' is it.

Getting started

Notes:

local

$ pip install -r requirements.txt
$ export OPENAI_API_KEY="your_openai_api_key"
$ python app.py

Go to another terminal window:

$ curl -X POST http://127.0.0.1:5001/ask_context -H "Content-Type: application/json" -d '{"sentence": "I am running for president of the United States"}'

docker (Mac M1)

The Dockerfile is prepared for you, but feel free to edit to your heart's content

$ docker build -t what-run-app:latest . 

$ docker run --rm -p 5001:5001 --env OPENAI_API_KEY="your_openai_api_key" what-run-app

Go to another terminal window:

$ curl -X POST http://127.0.0.1:5001/ask_context -H "Content-Type: application/json" -d '{"sentence": "I am running for president of the United States"}'

kubernetes

Import your OPENAI_API_KEY to your Kubernetes secret cough storage (first, replace 'your_openai_api_key'):

$ kubectl create secret generic openai-secret --from-literal=OPENAI_API_KEY="your_openai_api_key"

Install kind, create a cluster -- plenty of instructions online somewhere. :-)

$ kind load docker-image what-run-app:latest  

$ kubectl apply -f k8s-manifest.yaml 

$ kubectl port-forward svc/what-run-app-service 8080:80

If you made an oopsie and need to do an update:

$ kubectl rollout restart deployment/what-run-app 

Go to another terminal window:

$ curl -X POST http://127.0.0.1:8080/ask_context -H "Content-Type: application/json" -d '{"sentence": "I am running for president of the United States"}'

Diagram of the logic

graph TD;
    A[Client] -->|POST /ask_context| B[Flask App];
    B --> C{Check 'run' in sentence?};
    C -->|Yes| D[get_context];
    C -->|No| E[JSON comes back];
    D --> F[query_dictionary];
    F --> G[generate_url];
    G --> H[Return JSON with context, entries, URL];

    subgraph Flask Application
        B
        D
        F
        G
        H
    end

    subgraph OpenAI API
        D --> I[OpenAI Completion];
        F --> J[OpenAI Embedding];
    end

    subgraph Dictionary
        F --> K[Compute Similarity];
    end
Loading