典型的stream 二级页面打开 显示图片

import streamlit as st
from datetime import datetime
import sqlite3
import pathlib
import json,time,os
import pandas as pd




if 'conn' not in st.session_state:
    st.session_state.conn=sqlite3.connect(
        'ocr.sqlite',
        timeout=30.0,
        check_same_thread=False
    )
    st.session_state.cursor=st.session_state.conn.cursor()


def get_id(id):
    st.session_state.cursor.execute("SELECT id,done FROM pdf WHERE id=(?) AND done>0",(id,))
    if st.session_state.cursor.fetchone():
        st.session_state.cursor.execute("SELECT * FROM img WHERE pdf_id=(?)",(id,))
        rows=st.session_state.cursor.fetchall()
        cols=[desc[0] for desc in st.session_state.cursor.description]
        # cols=[desc[0] for desc in st.session_state.cursor.description]#获取键名
        return pd.DataFrame(rows,columns=cols)

    return False

# streamlit.query_params.get(‘id’)
id=st.query_params.get('id')
if not id:
    id=56
base_url = "/app/static/img"   
df=get_id(id)
df['path']=df['path'].apply(
    lambda name :f'<img src="{base_url}/{name}">'
)

st.markdown(
    df.to_html(escape=False, index=False),
    unsafe_allow_html=True
)
st.write()

发表回复