File size: 1,011 Bytes
fe7691a |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
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
def highlight_content(full_text, keyword):
if keyword:
# Highlight the keyword in the text
highlighted_text = full_text.replace(
keyword, f"<span class='highlight'>{keyword}</span>"
)
return highlighted_text
else:
return "No keyword entered for highlighting."
|