Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -18,7 +18,7 @@ load_dotenv()
|
|
18 |
|
19 |
# Configure Google Gemini API
|
20 |
genai.configure(api_key=os.getenv('GOOGLE_API_KEY'))
|
21 |
-
model = genai.GenerativeModel('gemini-
|
22 |
|
23 |
# Initialize session state variables if they don't exist
|
24 |
if 'submitted' not in st.session_state:
|
@@ -65,8 +65,6 @@ with col1:
|
|
65 |
uploaded_file = st.file_uploader("📄 Sube un archivo o imagen",
|
66 |
type=['txt', 'pdf', 'docx', 'jpg', 'jpeg', 'png'])
|
67 |
|
68 |
-
# Remove all the success message display code
|
69 |
-
|
70 |
if uploaded_file is not None:
|
71 |
file_type = uploaded_file.name.split('.')[-1].lower()
|
72 |
|
@@ -74,7 +72,6 @@ with col1:
|
|
74 |
if file_type in ['txt', 'pdf', 'docx']:
|
75 |
if file_type == 'txt':
|
76 |
file_content = uploaded_file.read().decode('utf-8')
|
77 |
-
# Remove success message code
|
78 |
|
79 |
elif file_type == 'pdf':
|
80 |
try:
|
@@ -83,7 +80,6 @@ with col1:
|
|
83 |
file_content = ""
|
84 |
for page in pdf_reader.pages:
|
85 |
file_content += page.extract_text() + "\n"
|
86 |
-
# Remove success message code
|
87 |
except Exception as e:
|
88 |
st.error(f"Error al leer el archivo PDF: {str(e)}")
|
89 |
file_content = ""
|
@@ -93,14 +89,16 @@ with col1:
|
|
93 |
import docx
|
94 |
doc = docx.Document(uploaded_file)
|
95 |
file_content = "\n".join([para.text for para in doc.paragraphs])
|
96 |
-
# Remove success message code
|
97 |
except Exception as e:
|
98 |
st.error(f"Error al leer el archivo DOCX: {str(e)}")
|
99 |
file_content = ""
|
100 |
|
101 |
-
#
|
102 |
-
st.write("**Vista previa del contenido:**")
|
103 |
-
st.write(file_content[:500] + "..." if len(file_content) > 500 else file_content)
|
|
|
|
|
|
|
104 |
|
105 |
# Set file type flag
|
106 |
is_image = False
|
@@ -117,7 +115,6 @@ with col1:
|
|
117 |
"data": image_bytes
|
118 |
}
|
119 |
]
|
120 |
-
# Remove success message code
|
121 |
|
122 |
# Set file type flag
|
123 |
is_image = True
|
|
|
18 |
|
19 |
# Configure Google Gemini API
|
20 |
genai.configure(api_key=os.getenv('GOOGLE_API_KEY'))
|
21 |
+
model = genai.GenerativeModel('gemini-2.0-flash')
|
22 |
|
23 |
# Initialize session state variables if they don't exist
|
24 |
if 'submitted' not in st.session_state:
|
|
|
65 |
uploaded_file = st.file_uploader("📄 Sube un archivo o imagen",
|
66 |
type=['txt', 'pdf', 'docx', 'jpg', 'jpeg', 'png'])
|
67 |
|
|
|
|
|
68 |
if uploaded_file is not None:
|
69 |
file_type = uploaded_file.name.split('.')[-1].lower()
|
70 |
|
|
|
72 |
if file_type in ['txt', 'pdf', 'docx']:
|
73 |
if file_type == 'txt':
|
74 |
file_content = uploaded_file.read().decode('utf-8')
|
|
|
75 |
|
76 |
elif file_type == 'pdf':
|
77 |
try:
|
|
|
80 |
file_content = ""
|
81 |
for page in pdf_reader.pages:
|
82 |
file_content += page.extract_text() + "\n"
|
|
|
83 |
except Exception as e:
|
84 |
st.error(f"Error al leer el archivo PDF: {str(e)}")
|
85 |
file_content = ""
|
|
|
89 |
import docx
|
90 |
doc = docx.Document(uploaded_file)
|
91 |
file_content = "\n".join([para.text for para in doc.paragraphs])
|
|
|
92 |
except Exception as e:
|
93 |
st.error(f"Error al leer el archivo DOCX: {str(e)}")
|
94 |
file_content = ""
|
95 |
|
96 |
+
# Remove these two lines to eliminate the preview
|
97 |
+
# st.write("**Vista previa del contenido:**")
|
98 |
+
# st.write(file_content[:500] + "..." if len(file_content) > 500 else file_content)
|
99 |
+
|
100 |
+
# Just show a success message instead
|
101 |
+
st.success(f"Archivo {file_type.upper()} cargado correctamente")
|
102 |
|
103 |
# Set file type flag
|
104 |
is_image = False
|
|
|
115 |
"data": image_bytes
|
116 |
}
|
117 |
]
|
|
|
118 |
|
119 |
# Set file type flag
|
120 |
is_image = True
|