Spaces:
Sleeping
Sleeping
Fix pdf viewer
Browse files- src/streamlit_app.py +12 -14
src/streamlit_app.py
CHANGED
|
@@ -7,6 +7,10 @@ from PIL import Image
|
|
| 7 |
import io
|
| 8 |
from dotenv import load_dotenv
|
| 9 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
load_dotenv()
|
| 11 |
|
| 12 |
MISTRAL_API_KEY = os.environ.get("MISTRAL_API_KEY")
|
|
@@ -163,23 +167,21 @@ def process_ocr(client, document_source):
|
|
| 163 |
include_image_base64=True
|
| 164 |
)
|
| 165 |
|
| 166 |
-
def display_pdf(
|
| 167 |
"""
|
| 168 |
Displays a PDF in Streamlit using an iframe.
|
| 169 |
|
| 170 |
Args:
|
| 171 |
-
|
| 172 |
"""
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
st.markdown(pdf_display, unsafe_allow_html=True)
|
| 177 |
|
| 178 |
def main():
|
| 179 |
"""
|
| 180 |
Main function to run the Streamlit app.
|
| 181 |
"""
|
| 182 |
-
st.set_page_config(page_title="OCR Facture avec Mistral", layout="wide")
|
| 183 |
|
| 184 |
# Sidebar: Authentication for Mistral API
|
| 185 |
if not MISTRAL_API_KEY:
|
|
@@ -221,13 +223,9 @@ def main():
|
|
| 221 |
if uploaded_file:
|
| 222 |
content = uploaded_file.read()
|
| 223 |
preview_content = uploaded_file
|
| 224 |
-
|
| 225 |
-
#
|
| 226 |
-
|
| 227 |
-
tmp.write(content)
|
| 228 |
-
pdf_path = tmp.name
|
| 229 |
-
|
| 230 |
-
display_pdf(pdf_path) # Display the uploaded PDF
|
| 231 |
|
| 232 |
# Prepare document source for OCR processing
|
| 233 |
document_source = {
|
|
|
|
| 7 |
import io
|
| 8 |
from dotenv import load_dotenv
|
| 9 |
|
| 10 |
+
# Configuration de la page - DOIT être la première commande Streamlit
|
| 11 |
+
st.set_page_config(page_title="OCR Facture avec Mistral", layout="wide")
|
| 12 |
+
|
| 13 |
+
|
| 14 |
load_dotenv()
|
| 15 |
|
| 16 |
MISTRAL_API_KEY = os.environ.get("MISTRAL_API_KEY")
|
|
|
|
| 167 |
include_image_base64=True
|
| 168 |
)
|
| 169 |
|
| 170 |
+
def display_pdf(content):
|
| 171 |
"""
|
| 172 |
Displays a PDF in Streamlit using an iframe.
|
| 173 |
|
| 174 |
Args:
|
| 175 |
+
content (bytes): The content of the PDF file.
|
| 176 |
"""
|
| 177 |
+
base64_pdf = base64.b64encode(content).decode("utf-8")
|
| 178 |
+
pdf_display = f'<iframe src="data:application/pdf;base64,{base64_pdf}" width="700" height="1000" type="application/pdf"></iframe>'
|
| 179 |
+
st.markdown(pdf_display, unsafe_allow_html=True)
|
|
|
|
| 180 |
|
| 181 |
def main():
|
| 182 |
"""
|
| 183 |
Main function to run the Streamlit app.
|
| 184 |
"""
|
|
|
|
| 185 |
|
| 186 |
# Sidebar: Authentication for Mistral API
|
| 187 |
if not MISTRAL_API_KEY:
|
|
|
|
| 223 |
if uploaded_file:
|
| 224 |
content = uploaded_file.read()
|
| 225 |
preview_content = uploaded_file
|
| 226 |
+
|
| 227 |
+
# Display the uploaded PDF
|
| 228 |
+
display_pdf(content)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 229 |
|
| 230 |
# Prepare document source for OCR processing
|
| 231 |
document_source = {
|