Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -25,10 +25,6 @@ if 'submitted' not in st.session_state:
|
|
| 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("""
|
|
@@ -67,32 +63,7 @@ with col1:
|
|
| 67 |
uploaded_file = st.file_uploader("📄 Sube un archivo o imagen",
|
| 68 |
type=['txt', 'pdf', 'docx', 'jpg', 'jpeg', 'png'])
|
| 69 |
|
| 70 |
-
#
|
| 71 |
-
st.markdown("""
|
| 72 |
-
<style>
|
| 73 |
-
.success {
|
| 74 |
-
font-weight: bold;
|
| 75 |
-
background-color: rgba(40, 167, 69, 0.2);
|
| 76 |
-
border-radius: 5px;
|
| 77 |
-
padding: 10px;
|
| 78 |
-
animation: fadeIn 0.3s ease-in;
|
| 79 |
-
}
|
| 80 |
-
@keyframes fadeIn {
|
| 81 |
-
from { opacity: 0; }
|
| 82 |
-
to { opacity: 1; }
|
| 83 |
-
}
|
| 84 |
-
</style>
|
| 85 |
-
""", unsafe_allow_html=True)
|
| 86 |
-
|
| 87 |
-
# Then in your success message display
|
| 88 |
-
if st.session_state.success_message:
|
| 89 |
-
current_time = time.time()
|
| 90 |
-
if current_time - st.session_state.success_time < 2:
|
| 91 |
-
st.markdown(f'<div class="success">{st.session_state.success_message}</div>', unsafe_allow_html=True)
|
| 92 |
-
else:
|
| 93 |
-
st.session_state.success_message = None
|
| 94 |
-
st.session_state.success_time = None
|
| 95 |
-
st.rerun()
|
| 96 |
|
| 97 |
if uploaded_file is not None:
|
| 98 |
file_type = uploaded_file.name.split('.')[-1].lower()
|
|
@@ -101,9 +72,7 @@ with col1:
|
|
| 101 |
if file_type in ['txt', 'pdf', 'docx']:
|
| 102 |
if file_type == 'txt':
|
| 103 |
file_content = uploaded_file.read().decode('utf-8')
|
| 104 |
-
#
|
| 105 |
-
st.session_state.success_message = f"Archivo de texto cargado correctamente: {uploaded_file.name}"
|
| 106 |
-
st.session_state.success_time = time.time()
|
| 107 |
|
| 108 |
elif file_type == 'pdf':
|
| 109 |
try:
|
|
@@ -112,9 +81,7 @@ with col1:
|
|
| 112 |
file_content = ""
|
| 113 |
for page in pdf_reader.pages:
|
| 114 |
file_content += page.extract_text() + "\n"
|
| 115 |
-
#
|
| 116 |
-
st.session_state.success_message = f"Archivo PDF cargado correctamente: {uploaded_file.name}"
|
| 117 |
-
st.session_state.success_time = time.time()
|
| 118 |
except Exception as e:
|
| 119 |
st.error(f"Error al leer el archivo PDF: {str(e)}")
|
| 120 |
file_content = ""
|
|
@@ -124,14 +91,12 @@ with col1:
|
|
| 124 |
import docx
|
| 125 |
doc = docx.Document(uploaded_file)
|
| 126 |
file_content = "\n".join([para.text for para in doc.paragraphs])
|
| 127 |
-
#
|
| 128 |
-
st.session_state.success_message = f"Archivo DOCX cargado correctamente: {uploaded_file.name}"
|
| 129 |
-
st.session_state.success_time = time.time()
|
| 130 |
except Exception as e:
|
| 131 |
st.error(f"Error al leer el archivo DOCX: {str(e)}")
|
| 132 |
file_content = ""
|
| 133 |
|
| 134 |
-
#
|
| 135 |
st.write("**Vista previa del contenido:**")
|
| 136 |
st.write(file_content[:500] + "..." if len(file_content) > 500 else file_content)
|
| 137 |
|
|
@@ -150,9 +115,7 @@ with col1:
|
|
| 150 |
"data": image_bytes
|
| 151 |
}
|
| 152 |
]
|
| 153 |
-
#
|
| 154 |
-
st.session_state.success_message = f"Imagen cargada correctamente: {uploaded_file.name}"
|
| 155 |
-
st.session_state.success_time = time.time()
|
| 156 |
|
| 157 |
# Set file type flag
|
| 158 |
is_image = True
|
|
|
|
| 25 |
st.session_state.submitted = False
|
| 26 |
if 'offer_result' not in st.session_state:
|
| 27 |
st.session_state.offer_result = ""
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
|
| 29 |
# Hide Streamlit menu and footer
|
| 30 |
st.markdown("""
|
|
|
|
| 63 |
uploaded_file = st.file_uploader("📄 Sube un archivo o imagen",
|
| 64 |
type=['txt', 'pdf', 'docx', 'jpg', 'jpeg', 'png'])
|
| 65 |
|
| 66 |
+
# Remove all the success message display code
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 67 |
|
| 68 |
if uploaded_file is not None:
|
| 69 |
file_type = uploaded_file.name.split('.')[-1].lower()
|
|
|
|
| 72 |
if file_type in ['txt', 'pdf', 'docx']:
|
| 73 |
if file_type == 'txt':
|
| 74 |
file_content = uploaded_file.read().decode('utf-8')
|
| 75 |
+
# Remove success message code
|
|
|
|
|
|
|
| 76 |
|
| 77 |
elif file_type == 'pdf':
|
| 78 |
try:
|
|
|
|
| 81 |
file_content = ""
|
| 82 |
for page in pdf_reader.pages:
|
| 83 |
file_content += page.extract_text() + "\n"
|
| 84 |
+
# Remove success message code
|
|
|
|
|
|
|
| 85 |
except Exception as e:
|
| 86 |
st.error(f"Error al leer el archivo PDF: {str(e)}")
|
| 87 |
file_content = ""
|
|
|
|
| 91 |
import docx
|
| 92 |
doc = docx.Document(uploaded_file)
|
| 93 |
file_content = "\n".join([para.text for para in doc.paragraphs])
|
| 94 |
+
# Remove success message code
|
|
|
|
|
|
|
| 95 |
except Exception as e:
|
| 96 |
st.error(f"Error al leer el archivo DOCX: {str(e)}")
|
| 97 |
file_content = ""
|
| 98 |
|
| 99 |
+
# Show preview with a header
|
| 100 |
st.write("**Vista previa del contenido:**")
|
| 101 |
st.write(file_content[:500] + "..." if len(file_content) > 500 else file_content)
|
| 102 |
|
|
|
|
| 115 |
"data": image_bytes
|
| 116 |
}
|
| 117 |
]
|
| 118 |
+
# Remove success message code
|
|
|
|
|
|
|
| 119 |
|
| 120 |
# Set file type flag
|
| 121 |
is_image = True
|