Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,6 +1,7 @@
|
|
1 |
import streamlit as st
|
2 |
import google.generativeai as genai
|
3 |
import os
|
|
|
4 |
from dotenv import load_dotenv
|
5 |
from styles import get_custom_css
|
6 |
from formulas import offer_formulas
|
@@ -24,6 +25,10 @@ if 'submitted' not in st.session_state:
|
|
24 |
st.session_state.submitted = False
|
25 |
if 'offer_result' not in st.session_state:
|
26 |
st.session_state.offer_result = ""
|
|
|
|
|
|
|
|
|
27 |
|
28 |
# Hide Streamlit menu and footer
|
29 |
st.markdown("""
|
@@ -61,6 +66,19 @@ with col1:
|
|
61 |
# Add file/image uploader here
|
62 |
uploaded_file = st.file_uploader("📄 Sube un archivo o imagen",
|
63 |
type=['txt', 'pdf', 'docx', 'jpg', 'jpeg', 'png'])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
64 |
if uploaded_file is not None:
|
65 |
file_type = uploaded_file.name.split('.')[-1].lower()
|
66 |
|
@@ -68,7 +86,9 @@ with col1:
|
|
68 |
if file_type in ['txt', 'pdf', 'docx']:
|
69 |
if file_type == 'txt':
|
70 |
file_content = uploaded_file.read().decode('utf-8')
|
71 |
-
|
|
|
|
|
72 |
|
73 |
elif file_type == 'pdf':
|
74 |
try:
|
@@ -77,7 +97,9 @@ with col1:
|
|
77 |
file_content = ""
|
78 |
for page in pdf_reader.pages:
|
79 |
file_content += page.extract_text() + "\n"
|
80 |
-
|
|
|
|
|
81 |
except Exception as e:
|
82 |
st.error(f"Error al leer el archivo PDF: {str(e)}")
|
83 |
file_content = ""
|
@@ -87,7 +109,9 @@ with col1:
|
|
87 |
import docx
|
88 |
doc = docx.Document(uploaded_file)
|
89 |
file_content = "\n".join([para.text for para in doc.paragraphs])
|
90 |
-
|
|
|
|
|
91 |
except Exception as e:
|
92 |
st.error(f"Error al leer el archivo DOCX: {str(e)}")
|
93 |
file_content = ""
|
@@ -111,7 +135,9 @@ with col1:
|
|
111 |
"data": image_bytes
|
112 |
}
|
113 |
]
|
114 |
-
|
|
|
|
|
115 |
|
116 |
# Set file type flag
|
117 |
is_image = True
|
|
|
1 |
import streamlit as st
|
2 |
import google.generativeai as genai
|
3 |
import os
|
4 |
+
import time
|
5 |
from dotenv import load_dotenv
|
6 |
from styles import get_custom_css
|
7 |
from formulas import offer_formulas
|
|
|
25 |
st.session_state.submitted = False
|
26 |
if 'offer_result' not in st.session_state:
|
27 |
st.session_state.offer_result = ""
|
28 |
+
if 'success_message' not in st.session_state:
|
29 |
+
st.session_state.success_message = None
|
30 |
+
if 'success_time' not in st.session_state:
|
31 |
+
st.session_state.success_time = None
|
32 |
|
33 |
# Hide Streamlit menu and footer
|
34 |
st.markdown("""
|
|
|
66 |
# Add file/image uploader here
|
67 |
uploaded_file = st.file_uploader("📄 Sube un archivo o imagen",
|
68 |
type=['txt', 'pdf', 'docx', 'jpg', 'jpeg', 'png'])
|
69 |
+
|
70 |
+
# Display success message if it exists and hasn't timed out
|
71 |
+
if st.session_state.success_message:
|
72 |
+
current_time = time.time()
|
73 |
+
# Show message for 3 seconds
|
74 |
+
if current_time - st.session_state.success_time < 3:
|
75 |
+
st.success(st.session_state.success_message)
|
76 |
+
else:
|
77 |
+
# Clear the message after timeout
|
78 |
+
st.session_state.success_message = None
|
79 |
+
st.session_state.success_time = None
|
80 |
+
st.rerun()
|
81 |
+
|
82 |
if uploaded_file is not None:
|
83 |
file_type = uploaded_file.name.split('.')[-1].lower()
|
84 |
|
|
|
86 |
if file_type in ['txt', 'pdf', 'docx']:
|
87 |
if file_type == 'txt':
|
88 |
file_content = uploaded_file.read().decode('utf-8')
|
89 |
+
# Set success message and time instead of showing directly
|
90 |
+
st.session_state.success_message = f"Archivo de texto cargado correctamente: {uploaded_file.name}"
|
91 |
+
st.session_state.success_time = time.time()
|
92 |
|
93 |
elif file_type == 'pdf':
|
94 |
try:
|
|
|
97 |
file_content = ""
|
98 |
for page in pdf_reader.pages:
|
99 |
file_content += page.extract_text() + "\n"
|
100 |
+
# Set success message and time instead of showing directly
|
101 |
+
st.session_state.success_message = f"Archivo PDF cargado correctamente: {uploaded_file.name}"
|
102 |
+
st.session_state.success_time = time.time()
|
103 |
except Exception as e:
|
104 |
st.error(f"Error al leer el archivo PDF: {str(e)}")
|
105 |
file_content = ""
|
|
|
109 |
import docx
|
110 |
doc = docx.Document(uploaded_file)
|
111 |
file_content = "\n".join([para.text for para in doc.paragraphs])
|
112 |
+
# Set success message and time instead of showing directly
|
113 |
+
st.session_state.success_message = f"Archivo DOCX cargado correctamente: {uploaded_file.name}"
|
114 |
+
st.session_state.success_time = time.time()
|
115 |
except Exception as e:
|
116 |
st.error(f"Error al leer el archivo DOCX: {str(e)}")
|
117 |
file_content = ""
|
|
|
135 |
"data": image_bytes
|
136 |
}
|
137 |
]
|
138 |
+
# Set success message and time instead of showing directly
|
139 |
+
st.session_state.success_message = f"Imagen cargada correctamente: {uploaded_file.name}"
|
140 |
+
st.session_state.success_time = time.time()
|
141 |
|
142 |
# Set file type flag
|
143 |
is_image = True
|