This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.conf.urls.static import static | |
urlpatterns = [ | |
path('admin/', admin.site.urls), | |
path('images/', include('images.urls')) | |
] | |
urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_URL) | |
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.db import models | |
class Image(models.Model): | |
file = models.ImageField(upload_to='images') | |
uploaded = models.DateTimeField(auto_now_add=True) | |
def __str__(self): | |
return str(self.pk) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.contrib import admin | |
from .models import Image | |
admin.site.register(Image) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.forms import ModelForm | |
from .models import Image | |
class ImageForm(ModelForm): | |
class Meta: | |
model = Image | |
fields = ['file'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% extends "base.html" %} | |
{% block body %} | |
<nav class="navbar navbar-light bg-light"> | |
<div class="container-fluid"> | |
<span class="navbar-brand mb-0 h1" style="font-size: medium;">Image to Text app</span> | |
</div> | |
</nav> | |
<div class="container-fluid"> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% load static %} | |
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<!-- Bootstrap CSS --> | |
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-uWxY/CJNBR+1zjPWmfnSnVxwRheevXITnMqoEIeG1LJrdI0GlVs/9cVSyPYXdcSF" crossorigin="anonymous"> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const alertBox = document.getElementById('alert-box') | |
const imageBox = document.getElementById('image-box') | |
const imageForm = document.getElementById('image-form') | |
const confirmBtn = document.getElementById('confirm-btn') | |
const input = document.getElementById('id_file') | |
const text = document.getElementById('text') | |
const csrf = document.getElementsByName('csrfmiddlewaretoken') | |
input.addEventListener('change', ()=> { | |
text.innerHTML = `<p>Select the text portion of the image</p>` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.shortcuts import render | |
from .models import Image | |
from .forms import ImageForm | |
from django.http import JsonResponse | |
import os, shutil | |
import glob | |
import cv2 | |
import pytesseract | |
def index(request): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
STATIC_URL = '/static/' | |
STATICFILES_DIRS = [BASE_DIR / 'static'] | |
MEDIA_URL = '/media/' | |
MEDIA_ROOT = BASE_DIR / 'media' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
python manage.py startapp <project-name> |
OlderNewer