Skip to content

Instantly share code, notes, and snippets.

View borodedamie's full-sized avatar
🏠
Working from home

Onaopemipo Oluborode borodedamie

🏠
Working from home
View GitHub Profile
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)
@borodedamie
borodedamie / models.py
Created October 25, 2021 18:03
Django OCR Project models.py
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)
@borodedamie
borodedamie / admins.py
Created October 25, 2021 18:06
Django OCR Project admins.py
from django.contrib import admin
from .models import Image
admin.site.register(Image)
@borodedamie
borodedamie / forms.py
Created October 25, 2021 18:08
Django OCR Project app forms.py
from django.forms import ModelForm
from .models import Image
class ImageForm(ModelForm):
class Meta:
model = Image
fields = ['file']
@borodedamie
borodedamie / index.html
Created October 25, 2021 18:10
index.html for Django OCR App
{% 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">
{% 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">
@borodedamie
borodedamie / main.js
Created October 25, 2021 18:20
Django OCR Project static file
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>`
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):
STATIC_URL = '/static/'
STATICFILES_DIRS = [BASE_DIR / 'static']
MEDIA_URL = '/media/'
MEDIA_ROOT = BASE_DIR / 'media'
python manage.py startapp <project-name>