summaryrefslogtreecommitdiff
path: root/Biz/Storybook.py
diff options
context:
space:
mode:
Diffstat (limited to 'Biz/Storybook.py')
-rwxr-xr-xBiz/Storybook.py22
1 files changed, 11 insertions, 11 deletions
diff --git a/Biz/Storybook.py b/Biz/Storybook.py
index 7d8f326..dbaf82a 100755
--- a/Biz/Storybook.py
+++ b/Biz/Storybook.py
@@ -56,6 +56,7 @@ PORT = int(os.environ.get("PORT", "3000"))
area = App.from_env()
app = ludic.web.LudicApp(debug=area == App.Area.Test)
+log = Log.setup(logging.DEBUG if area == App.Area.Test else logging.ERROR)
Sqids = sqids.Sqids()
@@ -70,14 +71,13 @@ def main() -> None:
def move(area: App.Area) -> None:
"""Run the application."""
- Log.setup(logging.DEBUG if area == App.Area.Test else logging.ERROR)
- logging.info("area: %s", area)
+ log.info("area: %s", area)
# during test, bind to beryllium's VPN address, else localhost
host = "100.127.197.132" if area == App.Area.Test else "127.0.0.1"
uvicorn.run(app, host=host, port=PORT)
-def test(area: App.Area = App.Area.Test) -> None:
+def test(area: App.Area) -> None:
"""Run the unittest suite manually."""
Test.run(area, [IndexTest, StoryTest])
@@ -238,7 +238,7 @@ def _openai_generate_text(
},
]
client = openai.OpenAI()
- logging.debug("calling openai.chat.completions.create")
+ log.debug("calling openai.chat.completions.create")
return client.chat.completions.create(
model="gpt-4o-mini",
messages=messages,
@@ -293,15 +293,15 @@ def generate_image(
Raises:
InternalServerError: when OpenAI API fails
"""
- logging.info("generating image %s.%s", story_id, page)
+ log.info("generating image %s.%s", story_id, page)
url = None
if area == App.Area.Test:
time.sleep(1)
url = "https://placehold.co/1024.png"
else:
client = openai.OpenAI()
- logging.debug("calling openai.images.generate")
- logging.debug("prompt: %s", image_prompt)
+ log.debug("calling openai.images.generate")
+ log.debug("prompt: %s", image_prompt)
image_response = client.images.generate(
model="dall-e-3",
prompt=image_prompt,
@@ -312,7 +312,7 @@ def generate_image(
url = image_response.data[0].url
if url is None:
msg = "error getting image from OpenAI"
- logging.error(msg)
+ log.error(msg)
raise ludic.web.exceptions.InternalServerError(msg)
image = Image(
story_id=story_id,
@@ -349,7 +349,7 @@ def generate_story_in_background(
inputs,
),
)
- logging.info("starting job %s", job_id)
+ log.info("starting job %s", job_id)
thread.start()
story = Story(id=story_id, inputs=inputs)
# save stuff
@@ -364,7 +364,7 @@ def generate_story_pages(
inputs: StoryInputs,
) -> list[Page]:
"""Upsert a new story."""
- logging.info("generating story pages %s", story_id)
+ log.info("generating story pages %s", story_id)
story_resp = generate_pages(inputs)
pages = [
Page(
@@ -527,7 +527,7 @@ def images_static(story_id: str, page: int) -> ludic.web.responses.Response:
if image["path"].exists():
return ludic.web.responses.FileResponse(image["path"])
msg = "images_static: image not found"
- logging.error(msg)
+ log.error(msg)
raise ludic.web.exceptions.NotFoundError(msg)