From 9476c49139b8c1fe00588df1cd0896fca6b7e4df Mon Sep 17 00:00:00 2001 From: James Ravenscroft Date: Sun, 15 Dec 2024 06:35:39 +0000 Subject: [PATCH] implement document view page --- docker-compose.yml | 3 +- penparse/penparse/settings.py | 5 +- .../migrations/0006_imagememo_model_name.py | 18 + penparse/webui/models.py | 3 + penparse/webui/tasks.py | 6 + penparse/webui/templates/document.html | 345 +++++++++--------- penparse/webui/views/__init__.py | 9 +- pyproject.toml | 1 + uv.lock | 2 + 9 files changed, 222 insertions(+), 170 deletions(-) create mode 100644 penparse/webui/migrations/0006_imagememo_model_name.py diff --git a/docker-compose.yml b/docker-compose.yml index f447c49..8771aa0 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -5,10 +5,9 @@ services: - 5672:5672 - 15672:15672 - vllm: image: vllm/vllm-openai:latest - command: "--model Qwen/Qwen2-VL-2B-Instruct-GPTQ-Int4 --quantization gptq" + command: "--model Qwen/Qwen2-VL-2B-Instruct-GPTQ-Int4 --quantization gptq " volumes: - ~/.cache/huggingface:/root/.cache/huggingface ports: diff --git a/penparse/penparse/settings.py b/penparse/penparse/settings.py index 8c92da9..dd9d93c 100644 --- a/penparse/penparse/settings.py +++ b/penparse/penparse/settings.py @@ -149,6 +149,7 @@ CELERY_BROKER_URL = "amqp://guest:guest@localhost/" OPENAI_API_BASE = os.getenv("OPENAI_API_BASE") -#OPENAI_API_KEY = os.getenv("OPENAI_API_KEY") -OPENAI_API_KEY = "test" +OPENAI_API_KEY = os.getenv("OPENAI_API_KEY") +#OPENAI_API_KEY = "test" OPENAI_MODEL = os.getenv("OPENAI_MODEL", "openai/gpt-4o") +#OPENAI_MODEL="ollama/llama3.2-vision" diff --git a/penparse/webui/migrations/0006_imagememo_model_name.py b/penparse/webui/migrations/0006_imagememo_model_name.py new file mode 100644 index 0000000..9cddff6 --- /dev/null +++ b/penparse/webui/migrations/0006_imagememo_model_name.py @@ -0,0 +1,18 @@ +# Generated by Django 4.2.16 on 2024-12-15 06:34 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('webui', '0005_imagememo_error_message'), + ] + + operations = [ + migrations.AddField( + model_name='imagememo', + name='model_name', + field=models.CharField(max_length=255, null=True), + ), + ] diff --git a/penparse/webui/models.py b/penparse/webui/models.py index 99bb5ea..b512eb4 100644 --- a/penparse/webui/models.py +++ b/penparse/webui/models.py @@ -3,6 +3,7 @@ from django.contrib.auth.base_user import BaseUserManager from django.db import models from uuid import uuid4 +from email.header import Charset class UserManager(BaseUserManager): @@ -58,6 +59,8 @@ class ImageMemo(models.Model): author = models.ForeignKey("User", on_delete=models.CASCADE, related_name="memos") + model_name = models.CharField(max_length=255, null=True) + created_at = models.DateTimeField(auto_now_add=True) updated_at = models.DateTimeField( auto_now=True, diff --git a/penparse/webui/tasks.py b/penparse/webui/tasks.py index 616e9d1..122bc04 100644 --- a/penparse/webui/tasks.py +++ b/penparse/webui/tasks.py @@ -16,6 +16,12 @@ If any words or letters are unclear, denote them with a '??'. For example if you were not sure whether a word is blow or blew you would transcribe it as '?blow?' +If a text is underlined followed by a newline that indicates that it is a header. Use markdown H2 to denote it as such. + +Make sure to add 2 newlines newlines between sections. + +Anything that looks visually like a bullet point should be treated as such. This includes lines starting with hyphens. Replace bullet point indicators with * in the interpretted text. + Please include whitespace and formatting for headings too. """ diff --git a/penparse/webui/templates/document.html b/penparse/webui/templates/document.html index d1ac6df..fe2049a 100644 --- a/penparse/webui/templates/document.html +++ b/penparse/webui/templates/document.html @@ -1,181 +1,200 @@ {% extends "main.html" %} {% load markdown_deux_tags %} {% load markdownify %} {% block content %}
-

Document View

-
-
-
-
-

- {{ document.title }} -

-
- - - - - - - - - - - - - -
Status: - - {{ document.status|title }} - -
Created:{{ document.created_at|date:"d/m/Y H:i" }}
Updated:{{ document.updated_at|date:"d/m/Y H:i" }}
-
-
-
-

Content:

- +

Document View

+
+
+
+
+

+ {{ document.title }} +

+
+ + + + + + + + + + + + + +
Status: + + {{ document.status|title }} + +
Created: + {{ document.created_at|date:"d/m/Y H:i:s" }} +
Updated: + {{ document.updated_at|date:"d/m/Y H:i:s" }} +
+
+
+
+

+ Content: +

+ +
+
+ {{ markup|safe }} +
+ +
+
+ + + + + Export + +
+ {% csrf_token %} + +
+
+
+
+
+ {{ document.title }} +
+
-
- {{ document.content|markdown }} -
- -
-
- - - - - Export - -
- {% csrf_token %} - -
-
-
-
- {{ document.title }} -
-
-
-
- - - - - Back to Dashboard - + + + + Back to Dashboard +
{% endblock %} {% block extra_js %} {% endblock %} diff --git a/penparse/webui/views/__init__.py b/penparse/webui/views/__init__.py index 51998f7..890ebd9 100644 --- a/penparse/webui/views/__init__.py +++ b/penparse/webui/views/__init__.py @@ -1,5 +1,6 @@ import logging import os +import markdown from django.contrib import messages from django.shortcuts import redirect, render @@ -27,7 +28,7 @@ def index(request): __all__ = [ "index", "document_thumbnail", - "document_image", + "document_image", "register", "dashboard", "settings", @@ -61,13 +62,15 @@ def view_document(request: HttpRequest, pk: str): # find document with given ID (pk path param) and current user id document = ImageMemo.objects.filter(id=pk, author__id=request.user.id).first() + doc_markup = markdown.markdown(document.content) + if not document: logger.debug(f"No memo found for user={request.user.id} and memo_id={pk}") return HttpResponse(content="Document not found", status=404) - - return render(request, "document.html", context={"document": document}) + + return render(request, "document.html", context={"document": document, "markup": doc_markup}) @login_required diff --git a/pyproject.toml b/pyproject.toml index 04c2b93..7ce2847 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -11,6 +11,7 @@ dependencies = [ "django>=4.2.16", "litellm>=1.54.1", "loguru>=0.7.3", + "markdown>=3.7", "pillow>=11.0.0", "pytest-django>=4.9.0", "pytest-loguru>=0.4.0", diff --git a/uv.lock b/uv.lock index 840974a..7492e59 100644 --- a/uv.lock +++ b/uv.lock @@ -1002,6 +1002,7 @@ dependencies = [ { name = "django-markdownify" }, { name = "litellm" }, { name = "loguru" }, + { name = "markdown" }, { name = "pillow" }, { name = "pytest" }, { name = "pytest-django" }, @@ -1018,6 +1019,7 @@ requires-dist = [ { name = "django-markdownify", specifier = ">=0.9.5" }, { name = "litellm", specifier = ">=1.54.1" }, { name = "loguru", specifier = ">=0.7.3" }, + { name = "markdown", specifier = ">=3.7" }, { name = "pillow", specifier = ">=11.0.0" }, { name = "pytest", specifier = ">=8.3.4" }, { name = "pytest-django", specifier = ">=4.9.0" },