-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgoog.py
52 lines (36 loc) · 1.37 KB
/
goog.py
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import io
import streamlit as st
from PIL import Image, ImageDraw
from google.cloud import vision
def _generate_annotated_image(content, annotations):
image_stream = io.BytesIO(content)
image = Image.open(image_stream)
for word in annotations:
bounding_poly = word.bounding_poly
draw = ImageDraw.Draw(image)
rect = [
bounding_poly.vertices[0].x, # left
bounding_poly.vertices[0].y, # top
bounding_poly.vertices[-2].x, # right
bounding_poly.vertices[-2].y # bottom
]
draw.rectangle(rect, outline='red')
return image
def gcp_detect_text(content):
client = vision.ImageAnnotatorClient()
image = vision.Image(content=content)
response = client.document_text_detection(image=image)
header_text = """<h3 style="font-family: Monaco">Google</h3>"""
st.markdown(header_text, unsafe_allow_html=True)
st.download_button(
label="Download transcipt",
data='\n'.join([row.description for row in response.text_annotations]),
key="google_download_transcript"
)
image_col, text_col = st.columns(2)
annotated_image = _generate_annotated_image(content, response.text_annotations)
with image_col:
st.image(annotated_image)
with text_col:
for row in response.text_annotations:
st.write(row.description)