Download ocr_utils.py from Shabdobhedi/OCR-Document-Search-App-Using_gemini-1: direct link, hf CLI and curl.
- Browser
- Download file 657 Bytes
-
https://huggingface.co/spaces/Shabdobhedi/OCR-Document-Search-App-Using_gemini-1/resolve/main/ocr_utils.py
- Command line
-
hf download hf://spaces/Shabdobhedi/OCR-Document-Search-App-Using_gemini-1/ocr_utils.py
-
curl -L -o ocr_utils.py https://huggingface.co/spaces/Shabdobhedi/OCR-Document-Search-App-Using_gemini-1/resolve/main/ocr_utils.py
657 Bytes
| import google.generativeai as genai | |
| from PIL import Image | |
| import streamlit as st | |
| import io | |
| GOOGLE_API_KEY = "AIzaSyAesEWBYNPVIw5dde2LiZDXWDDJ8by90XI" | |
| genai.configure(api_key=GOOGLE_API_KEY) | |
| model = genai.GenerativeModel("gemini-1.5-pro") | |
| def extract_text(image): | |
| # Ensure the image is in RGB mode | |
| if image.mode != 'RGB': | |
| image = image.convert('RGB') | |
| # Call the model's generate_content method with the PIL image | |
| response = model.generate_content( | |
| ["successfully extracts hindi and english text from the image and returns the extracted text in a structured format (plain text)", image] | |
| ) | |
| return response.text | |