refactor: Apply precommit autochanges

This commit is contained in:
Alivecow 2025-03-21 16:27:28 +01:00
parent e6da82595a
commit ab47d13938
5 changed files with 37 additions and 34 deletions

View file

@ -1,2 +1,2 @@
[run] [run]
omit = tests/* omit = tests/*

View file

@ -3,10 +3,13 @@
# For the full list of built-in configuration values, see the documentation: # For the full list of built-in configuration values, see the documentation:
# https://www.sphinx-doc.org/en/master/usage/configuration.html # https://www.sphinx-doc.org/en/master/usage/configuration.html
from __future__ import annotations
# -- Project information ----------------------------------------------------- # -- Project information -----------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information # https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information
import os import os
import sys import sys
sys.path.insert(0, os.path.abspath("../../senju")) sys.path.insert(0, os.path.abspath("../../senju"))
project = 'senju' project = 'senju'

View file

@ -16,4 +16,4 @@ documentation for details.
:caption: Contents: :caption: Contents:
usage usage
_modules/modules _modules/modules

View file

@ -1,15 +1,14 @@
from __future__ import annotations from __future__ import annotations
import os
from pathlib import Path from pathlib import Path
from flask import (Flask, redirect, render_template, request, url_for, from flask import (Flask, redirect, render_template, request,
send_from_directory) send_from_directory, url_for)
from senju.haiku import Haiku from senju.haiku import Haiku
from senju.store_manager import StoreManager from senju.store_manager import StoreManager
import os
app = Flask(__name__) app = Flask(__name__)
store = StoreManager(Path("/tmp/store.db")) store = StoreManager(Path("/tmp/store.db"))
@ -121,7 +120,8 @@ def generate_haiku():
API endpoint to generate a new haiku based on the provided prompt. API endpoint to generate a new haiku based on the provided prompt.
Accepts POST requests with JSON data containing a 'prompt' field. Accepts POST requests with JSON data containing a 'prompt' field.
Generates a haiku using the prompt, saves it to the store, and returns the ID. Generates a haiku using the prompt, saves it to the store,
and returns the ID.
Returns: Returns:
str: The ID of the newly created haiku if method is POST. str: The ID of the newly created haiku if method is POST.

View file

@ -12,7 +12,7 @@
<body> <body>
<div class="flex flex-col items-center justify-center min-h-screen bg-violet-900 text-white p-6"> <div class="flex flex-col items-center justify-center min-h-screen bg-violet-900 text-white p-6">
<div class="bg-white text-gray-900 p-8 rounded-xl shadow-lg max-w-lg w-full text-center transform transition duration-300 hover:scale-105 mb-8"> <div class="bg-white text-gray-900 p-8 rounded-xl shadow-lg max-w-lg w-full text-center transform transition duration-300 hover:scale-105 mb-8">
<h1 class="text-3xl font-bold text-violet-700 mb-4">Upload your image</h1> <h1 class="text-3xl font-bold text-violet-700 mb-4">Upload your image</h1>
<!-- File Upload container--> <!-- File Upload container-->
<div id="upload-area" class="flex items-center justify-center w-full"> <div id="upload-area" class="flex items-center justify-center w-full">
@ -27,7 +27,7 @@
<input id="dropzone-file" type="file" accept="image/*" class="hidden" /> <input id="dropzone-file" type="file" accept="image/*" class="hidden" />
</label> </label>
</div> </div>
<!-- Image Preview container--> <!-- Image Preview container-->
<div id="image-preview" class="w-full hidden"> <div id="image-preview" class="w-full hidden">
<div class="relative"> <div class="relative">
@ -39,17 +39,17 @@
</button> </button>
</div> </div>
</div> </div>
<!-- Error message --> <!-- Error message -->
<div id="error-message" class="mt-4 text-red-500 hidden"> <div id="error-message" class="mt-4 text-red-500 hidden">
Please upload an image first. Please upload an image first.
</div> </div>
<button id="submit-button" type="submit" class="mt-6 bg-violet-600 hover:bg-violet-700 text-white font-bold py-2 px-4 rounded transition duration-300"> <button id="submit-button" type="submit" class="mt-6 bg-violet-600 hover:bg-violet-700 text-white font-bold py-2 px-4 rounded transition duration-300">
Submit Submit
</button> </button>
</div> </div>
<div id="response-box" class="mt-8 bg-white text-gray-900 p-6 rounded-lg shadow-lg max-w-lg w-full text-center opacity-0 transition-opacity duration-500 ease-in-out"> <div id="response-box" class="mt-8 bg-white text-gray-900 p-6 rounded-lg shadow-lg max-w-lg w-full text-center opacity-0 transition-opacity duration-500 ease-in-out">
<h2 class="text-2xl font-semibold text-violet-700">AI recognized the following:</h2> <h2 class="text-2xl font-semibold text-violet-700">AI recognized the following:</h2>
<p id="ai-response" class="text-lg text-gray-700 mt-2 italic">Waiting for input...</p> <p id="ai-response" class="text-lg text-gray-700 mt-2 italic">Waiting for input...</p>
@ -62,7 +62,7 @@
</button> </button>
</div> </div>
</div> </div>
<!-- New generating haiku div that appears after "Yes" is clicked --> <!-- New generating haiku div that appears after "Yes" is clicked -->
<div id="generating-haiku-box" class="mt-8 bg-white text-gray-900 p-6 rounded-lg shadow-lg max-w-lg w-full text-center hidden transition-opacity duration-500 ease-in-out"> <div id="generating-haiku-box" class="mt-8 bg-white text-gray-900 p-6 rounded-lg shadow-lg max-w-lg w-full text-center hidden transition-opacity duration-500 ease-in-out">
<h2 class="text-2xl font-semibold text-violet-700">Generating Haiku</h2> <h2 class="text-2xl font-semibold text-violet-700">Generating Haiku</h2>
@ -103,24 +103,24 @@ Vote him, task complete.</h2>
const yesButton = document.getElementById('yes-button'); const yesButton = document.getElementById('yes-button');
const noButton = document.getElementById('no-button'); const noButton = document.getElementById('no-button');
const generatingHaikuBox = document.getElementById('generating-haiku-box'); const generatingHaikuBox = document.getElementById('generating-haiku-box');
const generatedHaikuBox = document.getElementById('generated-haiku-box'); const generatedHaikuBox = document.getElementById('generated-haiku-box');
let imageUploaded = false; let imageUploaded = false;
function handleFileSelect(event) { function handleFileSelect(event) {
const file = event.target.files[0]; const file = event.target.files[0];
if (file && file.type.startsWith('image/')) { if (file && file.type.startsWith('image/')) {
// Create a URL for the selected image // Create a URL for the selected image
const imageUrl = URL.createObjectURL(file); const imageUrl = URL.createObjectURL(file);
// Set the image source // Set the image source
previewImg.src = imageUrl; previewImg.src = imageUrl;
// Hide upload area and show image preview // Hide upload area and show image preview
uploadArea.classList.add('hidden'); uploadArea.classList.add('hidden');
imagePreview.classList.remove('hidden'); imagePreview.classList.remove('hidden');
errorMessage.classList.add('hidden'); errorMessage.classList.add('hidden');
// Set flag that image is uploaded // Set flag that image is uploaded
imageUploaded = true; imageUploaded = true;
} }
@ -128,14 +128,14 @@ Vote him, task complete.</h2>
function removeImage() { function removeImage() {
dropzoneFile.value = ''; dropzoneFile.value = '';
// Hide image // Hide image
imagePreview.classList.add('hidden'); imagePreview.classList.add('hidden');
uploadArea.classList.remove('hidden'); uploadArea.classList.remove('hidden');
URL.revokeObjectURL(previewImg.src); URL.revokeObjectURL(previewImg.src);
previewImg.src = ''; previewImg.src = '';
imageUploaded = false; imageUploaded = false;
responseBox.classList.add('opacity-0'); responseBox.classList.add('opacity-0');
generatingHaikuBox.classList.add('hidden'); generatingHaikuBox.classList.add('hidden');
@ -148,32 +148,32 @@ Vote him, task complete.</h2>
if (imageUploaded) { if (imageUploaded) {
// Hide error // Hide error
errorMessage.classList.add('hidden'); errorMessage.classList.add('hidden');
// Show response box // Show response box
responseBox.classList.remove('opacity-0'); responseBox.classList.remove('opacity-0');
// Example response // Example response
document.getElementById('ai-response').textContent = 'Dominic Monaghan interviewing Elijah Wood if he will wear wigs'; document.getElementById('ai-response').textContent = 'Dominic Monaghan interviewing Elijah Wood if he will wear wigs';
} else { } else {
errorMessage.classList.remove('hidden'); errorMessage.classList.remove('hidden');
uploadArea.classList.add('shake'); uploadArea.classList.add('shake');
setTimeout(() => { setTimeout(() => {
uploadArea.classList.remove('shake'); uploadArea.classList.remove('shake');
}, 600); }, 600);
} }
} }
function handleYesClick() { function handleYesClick() {
// Hide response box // Hide response box
responseBox.classList.add('opacity-0'); responseBox.classList.add('opacity-0');
// Show generating haiku box first // Show generating haiku box first
setTimeout(() => { setTimeout(() => {
responseBox.classList.add('hidden'); responseBox.classList.add('hidden');
generatingHaikuBox.classList.remove('hidden'); generatingHaikuBox.classList.remove('hidden');
// After a delay, hide generating box and show result // After a delay, hide generating box and show result
setTimeout(() => { setTimeout(() => {
generatingHaikuBox.classList.add('hidden'); generatingHaikuBox.classList.add('hidden');
@ -184,13 +184,13 @@ Vote him, task complete.</h2>
// Reset everything // Reset everything
removeImage(); removeImage();
} }
dropzoneFile.addEventListener('change', handleFileSelect); dropzoneFile.addEventListener('change', handleFileSelect);
removeImageBtn.addEventListener('click', removeImage); removeImageBtn.addEventListener('click', removeImage);
submitButton.addEventListener('click', handleSubmit); submitButton.addEventListener('click', handleSubmit);
yesButton.addEventListener('click', handleYesClick); yesButton.addEventListener('click', handleYesClick);
noButton.addEventListener('click', handleNoClick); noButton.addEventListener('click', handleNoClick);
// Add some CSS animation // Add some CSS animation
document.head.insertAdjacentHTML('beforeend', ` document.head.insertAdjacentHTML('beforeend', `
<style> <style>