looking for some solutions? You are welcome.

SOLVED: how can I stream text to html in flask

jiwonYun:
def gen(fr):
conn=login_db()
while True:
    jpg_bytes = fr.get_jpg_bytes(conn)[0]
    yield (b'--frame\r\n'
           b'Content-Type: image/jpeg\r\n\r\n' + jpg_bytes + b'\r\n\r\n')

@app.route('/get_img') def get_img():
return Response(stream_with_context(gen2()), mimetype='multipart/x-mixed-replace); 

hello i am using flask to stream image, text to html templates. i already succeed to streaming image to html in real time. but i really dont know how to send text to html. below is my index.html

<img src = ""/>

i used this html tag to recieve img in realtime. do you know how to recieve text?

def select_img(conn,id):

    with conn.cursor() as cursor :  
        sql = '''
            select name,similarity,img
                from test_fol
            where id = %s;              
            '''                   
        cursor.execute(sql,(id)) 
    row = cursor.fetchone()
    nparr = np.fromstring(row['img'],np.uint8)

    tmp = cv2.imdecode(nparr,cv2.IMREAD_UNCHANGED)
    ret, jpg = cv2.imencode('.jpg',tmp)
    res = jpg.tobytes()

    name = row['name']
    similarity = row['similarity']
    return(res,name,similarity)

this select_img() in dbMgr.py. variable name and similarity are string type.



Posted in S.E.F
via StackOverflow & StackExchange Atomic Web Robots
Share:

No comments:

Recent