from fastapi import FastAPI, File, UploadFile from fastapi.responses import HTMLResponse from io import BytesIO import pytesseract from PIL import Image import cv2 import numpy as np # Initialize FastAPI app app = FastAPI() import subprocess def install_tesseract(): try: subprocess.run(['apt-get', 'update'], check=True) subprocess.run(['apt-get', 'install', '-y', 'tesseract-ocr'], check=True) except subprocess.CalledProcessError as e: print(f"Error installing Tesseract: {e}") install_tesseract() # Serve static files (images, etc.) # app.mount("/static", StaticFiles(directory="static"), name="static") # Not needed if you're not saving the images # Home route @app.get("/", response_class=HTMLResponse) async def home(): html_content = """
Quickly extract text from your uploaded images!