Spaces:
Sleeping
Sleeping
Create pages/opciones.py
Browse files- pages/opciones.py +37 -0
pages/opciones.py
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import pandas as pd
|
| 3 |
+
import os
|
| 4 |
+
import tempfile
|
| 5 |
+
import matplotlib.pyplot as plt
|
| 6 |
+
from matplotlib.backends.backend_pdf import PdfPages
|
| 7 |
+
|
| 8 |
+
def show():
|
| 9 |
+
st.title("馃敡 Opciones")
|
| 10 |
+
|
| 11 |
+
def generar_pdf(df, titulo, filename):
|
| 12 |
+
pdf_path = os.path.join(tempfile.gettempdir(), filename)
|
| 13 |
+
with PdfPages(pdf_path) as pdf:
|
| 14 |
+
plt.figure()
|
| 15 |
+
plt.axis('tight')
|
| 16 |
+
plt.axis('off')
|
| 17 |
+
plt.table(cellText=df.values, colLabels=df.columns, cellLoc='center', loc='center')
|
| 18 |
+
plt.title(titulo)
|
| 19 |
+
pdf.savefig()
|
| 20 |
+
plt.close()
|
| 21 |
+
return pdf_path
|
| 22 |
+
|
| 23 |
+
if st.button("Comprar"):
|
| 24 |
+
st.success("Funci贸n de compra en desarrollo...")
|
| 25 |
+
|
| 26 |
+
if st.button("Descargar PDF"):
|
| 27 |
+
if 'pedidos' in st.session_state and st.session_state.pedidos:
|
| 28 |
+
pedidos_df = pd.DataFrame(st.session_state.pedidos)
|
| 29 |
+
pdf_file = generar_pdf(pedidos_df, "Pedidos de Saz贸n Burger", "pedidos.pdf")
|
| 30 |
+
st.download_button(
|
| 31 |
+
label="馃摜 Descargar PDF",
|
| 32 |
+
data=open(pdf_file, 'rb').read(),
|
| 33 |
+
file_name="pedidos.pdf",
|
| 34 |
+
mime="application/pdf"
|
| 35 |
+
)
|
| 36 |
+
else:
|
| 37 |
+
st.warning("No hay pedidos para descargar.")
|