8000 Adding more links and slight reorg by veekaybee · Pull Request #1 · normconf/goodies · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Adding more links and slight reorg #1

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

Closed
wants to merge 4 commits into from
Closed
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
Binary file modified .DS_Store
Binary file not shown.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@
/app/__pycache__
/app/*.env

app/__pycache__
app/__pycache__

.DS_Store
12 changes: 5 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
FROM python:3.10-slim

# Install python/pip

COPY ./app /app

COPY ./requirements.txt /app/requirements.txt

RUN pip install --no-cache-dir -r app/requirements.txt
# Copy requirements before building so as to not invalidate build cache
COPY requirements.txt app/requirements.txt
WORKDIR /app
RUN pip install -r /app/requirements.txt
COPY . /app

ENV ENV="INTEGRATION"

Expand Down
18 changes: 10 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@ Using latent-space embeddings we synthesize every arxiv deep learning finding in
....


| API | endpoint | description |
|-----| ---------| ------------ |
| normconf | api.normconf.com/normconf | ASCII Goodness |
| random_goodies | api.normconf.com/random_goodies | Random Goodness |
| allthegoodies | api.normconf.com/allthegoodies | Too Much Goodness |
| schdeule | api.normconf.com/schedule | Normconf Schedule Goodness |
| API | endpoint | description |
| -------------- | ------------------------------- | -------------------------- |
| normconf | api.normconf.com/normconf | ASCII Goodness |
| random_goodies | api.normconf.com/random_goodies | Random Goodness |
| schedule | api.normconf.com/schedule | Normconf Schedule Goodness |


Ideas
Expand All @@ -21,5 +20,8 @@ Ideas
3 pizza-delimited values and maybe a link to that twitter conversation about delimiters


# TO DO
- remove pycache from repo
# To Develop Locally:

1. Clone and go to repo root
2. `make integration` to build and run locally with Poetry (requires Python 3.10+)
3. `make run` to build and run Docker image locally
Binary file modified app/.DS_Store
Binary file not shown.
4 changes: 2 additions & 2 deletions app/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,5 @@ def configure_logger() -> Logger:
return structlog.get_logger()


goodies_path = 'app/goodies/'
surprises = [goodies_path + file for file in listdir(Path(goodies_path))]
goodies_path = "app/goodies/media/"
surprises = [goodies_path + file for file in listdir(Path(goodies_path))]
4 changes: 4 additions & 0 deletions app/goodies/links.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
https://www.youtube.com/watch?v=eBGIQ7ZuuiU
https://www.destroyallsoftware.com/talks/wat
https://www.ftrain.com/wwic
https://e2eml.school/interviewing_2022.html
File renamed without changes.
File renamed without changes
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
the zen of normcore
sometimes it’s hardcore science,
but deep down in our heart,
we know that a for loop in a python file,
we know that a for loop in a Python file,
can outperform the state of the art
all programs live in a system
forgetting this will make somebody sad.
this algorithm has the best metrics,
so why is everone getting the same ad?
so why is everyone getting the same ad?
try to think about your tools,
try to limit your needs,
try not not to be the optimal model,
Expand Down
1 change: 0 additions & 1 deletion app/goodies/rickroll.txt

This file was deleted.

16 changes: 8 additions & 8 deletions app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"http://localhost",
"http://localhost:8000",
"https://localhost:8000",
"https://localhost:443"
"https://localhost:443",
]

middleware = [
Expand All @@ -40,12 +40,12 @@

# App Setup
app = FastAPI(
title="NormConf Goodies App",
description="Send random goods to the normies",
docs_url="/docs",
openapi_url="/api",
middleware=middleware,
)
title="NormConf Goodies App",
description="Send random goods to the normies",
docs_url="/docs",
openapi_url="/api",
middleware=middleware,
)


@app.get("/", tags=["health"], response_model=HealthCheck, name="App Health Check")
Expand All @@ -67,7 +67,7 @@ def info(settings_: Settings = Depends(get_settings)):


@app.get("/v1", tags=["status"], name="V1 Status Check")
async def root():
def root():
return {"message": f"{settings.app_version}"}


Expand Down
91 changes: 45 additions & 46 deletions app/normconf.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import structlog
from fastapi import APIRouter
from fastapi.responses import FileResponse, StreamingResponse
from fastapi.responses import FileResponse, StreamingResponse, PlainTextResponse, Response
from pandas import read_html
from requests import post

Expand All @@ -19,10 +19,11 @@

normie_router = APIRouter(responses={404: {"description": "Auth router not found"}})

goodies_path = 'app/goodies/'
goodies_path = "app/goodies/"

@normie_router.get('/schedule')
def get_schedule(as_markdown:bool=True, as_csv:bool=False, as_excel:bool=False):

@normie_router.get("/schedule")
def get_schedule(as_markdown: bool = True, as_csv: bool = False, as_excel: bool = False):
"""Return NormConf Schedule\n

Args:\n
Expand All @@ -33,78 +34,76 @@ def get_schedule(as_markdown:bool=True, as_csv:bool=False, as_excel:bool=False):
Returns:\n
DataFrame: Returns schedule as Pandas DataFrame
"""
schedule = read_html('https://normconf.com/', header=0)[0]
schedule = read_html("https://normconf.com/", header=0)[0]

if sum([as_markdown, as_csv, as_excel]) != 1:
raise ValueError("Only one file return type expected, but got multiple or none!")

if as_csv:
return schedule.to_csv()

elif as_excel:
return schedule.to_excel("ye_olde_nc_schedule.xlsx", sheet_name='Ye Olde NormConf Schedule')
elif as_excel:
return schedule.to_excel(
"ye_olde_nc_schedule.xlsx", sheet_name="Ye Olde NormConf Schedule"
)

elif as_markdown:
return schedule.to_markdown(tablefmt="github", index=False)

return schedule

@normie_router.get('/normconf')

@normie_router.get("/normconf")
def get_normconf():
"""Return ASCII file of normconf
"""
return FileResponse(Path(f'{goodies_path}normconf_ascii.txt'))
"""Return ASCII file of normconf"""
return FileResponse(Path(f"{goodies_path}normconf_ascii.txt"))


@normie_router.get('/zen')
@normie_router.get("/zen")
def get_zen():
"""Return Zen of Normcore by Vincent D. Warmerdam
"""
return FileResponse(Path(f'{goodies_path}zen_of_normcore.txt'))
"""Return Zen of Normcore by Vincent D. Warmerdam"""
return FileResponse(Path(f"{goodies_path}zen_of_normcore.txt"))


@normie_router.post("/get_talk")
def get_talk(request: GetTalkRequest): # -> TalkResponse:

@normie_router.post('/get_talk')
def get_talk(request: GetTalkRequest): #-> TalkResponse:

API_URL = "https://api-inference.huggingface.co/models/gpt2"
headers = {"Authorization": f"Bearer {settings.hugging_face_api_key}"}
response = post(API_URL, headers=headers, json=request.talk_title)

response = post(API_URL, headers=headers, json=request.talk_title)

content = loads(response.text)[0]["generated_text"]

return TalkResponse(talk_content=content)

@normie_router.get('/random_goodies')

@normie_router.get("/random_goodies")
def get_random_goodie():
"""Return random goodie file from goodies directory
"""
goodie = choice(surprises)
"""Return random goodie file from goodies directory"""
link_path = Path("app/goodies/links.txt")
links = open(link_path).read().splitlines()

if goodie.endswith('.png'):
return FileResponse(goodie,
media_type='image/png',
filename=goodie[len(goodies_path):],
headers={'Cache-Control': 'no-cache'})
goodie = choice(surprises)

return FileResponse(Path(f'{goodie}'), headers={'Cache-Control': 'no-cache'})
if goodie.endswith(".png"):
return FileResponse(
goodie,
media_type="image/png",
filename=goodie[len(goodies_path) :],
headers={"Cache-Control": "no-cache"},
)

return FileResponse(Path(f"{goodie}"), headers={"Cache-Control": "no-cache"})

@normie_router.get('/allthegoodies')
def get_goodies():
"""Return all the goodes from goodies directory
"""

goodies_len = len(goodies_path)
zip_io = BytesIO()
with ZipFile(zip_io, mode='w', compression=ZIP_DEFLATED) as temp_zip:
for file in surprises:
if "rickroll" in file:
continue
temp_zip.write(file, file[goodies_len:])
@normie_router.get("/wisdom", response_class=Response)
def get_random_wisdom():
"""Get a random hand-picked link"""

return StreamingResponse(iter([zip_io.getvalue()]),
media_type="application/x-zip-compressed",
headers = { "Content-Disposition": f"attachment; filename=allthegoodies.zip"}
)
link_path = Path("app/goodies/links.txt")
links = open(link_path).read().splitlines()

random_link = choice(links)

return Response(random_link + "\n")
10 changes: 10 additions & 0 deletions app/test_main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from fastapi.testclient import TestClient

from .main import app

client = TestClient(app)


def test_read_main():
response = client.get("/")
assert response.status_code == 200
12 changes: 6 additions & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@ description = ""
authors = ["Ben Labaschin <benjaminlabaschin@gmail.com>"]

[tool.poetry.dependencies]
python = "3.10.4"
uvicorn = "^0.17.6"
boto3 = "^1.23.9"
fastapi = "^0.78.0"
pydantic = "^1.9.1"
lxml = "^4.9.1"
openpyxl = "^3.0.10"
pandas = "^1.4.2"
requests = "^2.27.1"
pydantic = "^1.9.1"
python = "3.10.4"
python-dotenv = "^0.20.0"
structlog = "^22.1.0"
lxml = "^4.9.1"
tabulate = "^0.9.0"
openpyxl = "^3.0.10"
requests = "^2.27.1"
uvicorn = "^0.17.6"

[tool.poetry.dev-dependencies]
ipykernel = "^6.13.0"
Expand Down
0