Shabdobhedi commited on
Commit
d452588
·
verified ·
1 Parent(s): 3cfbfe7

Update ocr_utils.py

Browse files
Files changed (1) hide show
  1. ocr_utils.py +25 -34
ocr_utils.py CHANGED
@@ -1,34 +1,25 @@
1
- import google.generativeai as genai
2
- from PIL import Image
3
- import streamlit as st
4
- import io
5
-
6
-
7
- GOOGLE_API_KEY = "AIzaSyAesEWBYNPVIw5dde2LiZDXWDDJ8by90XI"
8
- genai.configure(api_key=GOOGLE_API_KEY)
9
- model = genai.GenerativeModel("gemini-1.5-pro")
10
-
11
-
12
- def extract_text(image):
13
- # Ensure the image is in RGB mode
14
- if image.mode != 'RGB':
15
- image = image.convert('RGB')
16
-
17
- # Call the model's generate_content method with the PIL image
18
- response = model.generate_content(
19
- ["successfully extracts hindi and english text from the image and returns the extracted text in a structured format (plain text)", image]
20
- )
21
-
22
- return response.text
23
-
24
-
25
- def highlight_content(full_text, keyword):
26
- if keyword:
27
- # Highlight the keyword in the text
28
- highlighted_text = full_text.replace(
29
- keyword, f"<span class='highlight'>{keyword}</span>"
30
- )
31
-
32
- return highlighted_text
33
- else:
34
- return "No keyword entered for highlighting."
 
1
+ import google.generativeai as genai
2
+ from PIL import Image
3
+ import streamlit as st
4
+ import io
5
+
6
+
7
+ GOOGLE_API_KEY = "AIzaSyAesEWBYNPVIw5dde2LiZDXWDDJ8by90XI"
8
+ genai.configure(api_key=GOOGLE_API_KEY)
9
+ model = genai.GenerativeModel("gemini-1.5-pro")
10
+
11
+
12
+ def extract_text(image):
13
+ # Ensure the image is in RGB mode
14
+ if image.mode != 'RGB':
15
+ image = image.convert('RGB')
16
+
17
+ # Call the model's generate_content method with the PIL image
18
+ response = model.generate_content(
19
+ ["successfully extracts hindi and english text from the image and returns the extracted text in a structured format (plain text)", image]
20
+ )
21
+
22
+ return response.text
23
+
24
+
25
+