SyedUmairHasan/TextDetection
0
1import streamlit as st2from streamlit_drawable_canvas import st_canvas3import cv24import requests5import time6import os7 8st.title("Text Detection")9 10def signaturefunk():11 flag = False12 # Specify canvas parameters in application13 stroke_width = st.sidebar.slider("Stroke width: ", 5, 20, 6)14 stroke_color = st.sidebar.color_picker("Stroke color hex: ","#ffffff")15 # Create a canvas component16 canvas_result = st_canvas(17 fill_color="rgba(255, 165, 0, 0.3)", # Fixed fill color with some opacity18 stroke_width=stroke_width,19 stroke_color=stroke_color,20 #background_color="#eee",21 background_color="black",22 height=250,23 drawing_mode='freedraw',24 display_toolbar=st.sidebar.checkbox("Display toolbar", True)25 )26 27 # Do something interesting with the image data and paths28 if st.button('Submit'):29 if canvas_result.image_data is not None:30 cv2.imwrite(f"img.jpg", canvas_result.image_data)31 flag = True32 33 34 if flag == True:35 with open('img.jpg', 'rb') as f:36 data = f.read()37 r = requests.post(os.environ["endpoint"],data=data,headers={"Ocp-Apim-Subscription-Key":os.environ["key"],"Content-Type": "application/octet-stream"})38 time.sleep(3)39 r2 = requests.get(r.headers['Operation-Location'],headers={"Ocp-Apim-Subscription-Key":os.environ["key"]})40 my_dict = {}41 print(r2.json())42 for line in r2.json()['analyzeResult']['readResults'][0]['lines']:43 st.markdown(f"<h1 style='text-align:center;font-family:cursive;'>{line['text']}</h1>",unsafe_allow_html=True)44 for word in line['words']:45 my_dict[word['text']] = word['confidence']46 for key in my_dict:47 st.metric(label='',value=f"{key}", delta=f"{my_dict[key]*100} %")48 st.progress(my_dict[key])49 flag = False50 51 52signaturefunk()