Skip to content

Contrib/logogenerator #378

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions contrib/wordlyworks/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
NOUN_PROJECT_KEY= c87a8c5fb6354664af47395db447cc72
NOUN_PROJECT_SECRET= 3809573e72fc4125b4c33782b0c74229
15 changes: 15 additions & 0 deletions contrib/wordlyworks/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Setup

```
git clone https://github.com/MLDSAI/OpenAdapt.git
cd OpenAdapt/contrib/wordlyworks
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
cp .env.example .env # open .env and fill in the values
```

# Run
```
python main.py
```
46 changes: 46 additions & 0 deletions contrib/wordlyworks/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
"""
Use named entity recognition to extract entities from text description (e.g. Spacy)
Download SVGs from https://thenounproject.com/
Ask large language model to arrange
Generate combined SVG
Run through e.g. Stable Diffusion and/or ask large language model to generate animation code
"""

from pprint import pformat
from requests_oauthlib import OAuth1
import os
import requests
from contrib.wordlyworks import ner.ner

from dotenv import load_dotenv
from loguru import logger
import ner
#from TheNounProjectAPI import API


load_dotenv()


def main():
key = os.environ["NOUN_PROJECT_KEY"]
secret = os.environ["NOUN_PROJECT_SECRET"]
logger.info(f"{key=} {secret=}")


auth = OAuth1(key, secret)
endpoint = "https://api.thenounproject.com/v2/icon/1"

response = requests.get(endpoint, auth=auth)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consult the noun project API to determine which URL to use in order to search, and search for each of the entities returned by get_entities

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good 👍 based on my current research I think we should use their blacklist endpoint. It allows for more control over their icons relatively compared to their other APIs.

The blacklist API is pretty neat if there are irrelevant or inappropriate terms. They will automatically be excluded compared to their icons endpoint.

I'll have some stuff for us to chat about on Friday!

logger.info(f"response=\n{pformat(response.json())}")

if 0:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@abrichr just a question. Why remove all this code? The if 0 part I understand why. However, the response =... isn't that used for the endpoint to get data from the noun project based on the API key?

Additionally, logger.info... I think I understand why that needs to be removed since this gets the request and prints it to the logs (for debugging purposes)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nevermind I think I know why we need to remove all of this because the blacklist function will send a get request on behalf of the app.

api = API(key=key, secret=secret)
icons = api.get_icons_by_term("goat", public_domain_only=True, limit=2)
for icon in icons:
print("Icon's term:", icon.term)
print("This icon's tags:", ", ".join(tag.slug for tag in icon.tags))
print("Uploader's username:", icon.uploader.username)


if __name__ == "__main__":
main()
24 changes: 24 additions & 0 deletions contrib/wordlyworks/ner.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import spacy


def ner():
nlp = spacy.load("en_core_web_sm")

text_description = '''
Apple Inc. is planning to open a new factory in Austin, Texas.
The plan will reportedly cost $1 billion and create jobs for 5,000 people.
Apple's CEO, Tim Cook, will oversee the new project.
'''

document_object = nlp(text_description)

for entity in document_object.ents:
print(f"{entity.text}, ({entity.label_})")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to print, just return the relevant entities.

Also, please move this function to main.py and name it get_entities. It should also accept a string as an argument.



if __name__ == "__main__":
ner()




6 changes: 6 additions & 0 deletions contrib/wordlyworks/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
loguru==0.7.0
python-dotenv==1.0.0
#TheNounProjectAPI==1.0.5