Update app.py
Browse files
app.py
CHANGED
@@ -130,15 +130,13 @@ def show_file_operations(file_path, sequence_number):
|
|
130 |
col01, col02, col1, col2, col3 = st.columns(5)
|
131 |
with col01:
|
132 |
st.write(os.path.basename(file_path))
|
133 |
-
#with col02:
|
134 |
-
#st.write(file_path)
|
135 |
with col1:
|
136 |
edit_key = f"edit_{unique_key}_{sequence_number}"
|
137 |
-
if st.button(f"✏️ Edit", key=edit_key):
|
138 |
-
with open(file_path, "r") as f:
|
139 |
-
|
140 |
-
text_area_key = f"text_area_{unique_key}_{sequence_number}"
|
141 |
-
file_content = st.text_area("Edit the file content:", value=file_content, height=250, key=text_area_key)
|
142 |
|
143 |
with col2:
|
144 |
save_key = f"save_{unique_key}_{sequence_number}"
|
@@ -157,6 +155,36 @@ def show_file_operations(file_path, sequence_number):
|
|
157 |
|
158 |
file_sequence_numbers = {}
|
159 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
160 |
def show_download_links(subdir):
|
161 |
global file_sequence_numbers
|
162 |
for file in list_files(subdir):
|
@@ -196,46 +224,6 @@ def get_download_link(file):
|
|
196 |
b64 = base64.b64encode(bytes).decode()
|
197 |
href = f'<a href="data:file/octet-stream;base64,{b64}" download=\'{os.path.basename(file)}\'>Download: {os.path.basename(file)}</a>'
|
198 |
return href
|
199 |
-
|
200 |
-
def show_file_content(file_path):
|
201 |
-
_, file_extension = os.path.splitext(file_path)
|
202 |
-
try:
|
203 |
-
|
204 |
-
if file_extension in ['.png', '.jpg', '.jpeg']:
|
205 |
-
image_url = file_path.replace('File:','')
|
206 |
-
st.write('Image URL:' + image_url)
|
207 |
-
# Check if the base_url needs to be prepended
|
208 |
-
#if base_url and not file_path.startswith(("http://", "https://")):
|
209 |
-
#image_url = os.path.join(base_url, file_path)
|
210 |
-
|
211 |
-
# Create a Markdown link to view the image
|
212 |
-
markdown_link = f"[![Image]({image_url})]({image_url})" #file_path
|
213 |
-
st.markdown(markdown_link, unsafe_allow_html=True)
|
214 |
-
|
215 |
-
#if file_extension in ['.png', '.jpg', '.jpeg']:
|
216 |
-
# with open(file_path, "rb") as file:
|
217 |
-
# img = Image.open(file)
|
218 |
-
# st.image(img, caption=os.path.basename(file_path))
|
219 |
-
#if file_extension in ['.png', '.jpg', '.jpeg']:
|
220 |
-
# st.image(file_path)
|
221 |
-
elif file_extension in ['.md', '.markdown']:
|
222 |
-
with open(file_path, "r") as file:
|
223 |
-
content = file.read()
|
224 |
-
edited_content = st.text_area(f"Edit {os.path.basename(file_path)}", value=content, height=250)
|
225 |
-
if st.button(f"Save {os.path.basename(file_path)}"):
|
226 |
-
with open(file_path, "w") as file:
|
227 |
-
file.write(edited_content)
|
228 |
-
st.success(f"Saved {os.path.basename(file_path)}!")
|
229 |
-
elif file_extension in ['.html', '.txt']:
|
230 |
-
with open(file_path, "r") as file:
|
231 |
-
st.markdown(file.read(), unsafe_allow_html=True)
|
232 |
-
elif file_extension in ['.pdf']:
|
233 |
-
pdf_file = open(file_path, "rb")
|
234 |
-
base64_pdf = base64.b64encode(pdf_file.read()).decode('utf-8')
|
235 |
-
pdf_display = f'<iframe src="data:application/pdf;base64,{base64_pdf}" width="700" height="1000" type="application/pdf"></iframe>'
|
236 |
-
st.markdown(pdf_display, unsafe_allow_html=True)
|
237 |
-
except Exception as e:
|
238 |
-
st.error(f"Error reading file {file_path}: {e}")
|
239 |
|
240 |
|
241 |
|
|
|
130 |
col01, col02, col1, col2, col3 = st.columns(5)
|
131 |
with col01:
|
132 |
st.write(os.path.basename(file_path))
|
|
|
|
|
133 |
with col1:
|
134 |
edit_key = f"edit_{unique_key}_{sequence_number}"
|
135 |
+
#if st.button(f"✏️ Edit", key=edit_key):
|
136 |
+
#with open(file_path, "r") as f:
|
137 |
+
# file_content = f.read()
|
138 |
+
#text_area_key = f"text_area_{unique_key}_{sequence_number}"
|
139 |
+
#file_content = st.text_area("Edit the file content:", value=file_content, height=250, key=text_area_key)
|
140 |
|
141 |
with col2:
|
142 |
save_key = f"save_{unique_key}_{sequence_number}"
|
|
|
155 |
|
156 |
file_sequence_numbers = {}
|
157 |
|
158 |
+
|
159 |
+
def show_file_content(file_path):
|
160 |
+
_, file_extension = os.path.splitext(file_path)
|
161 |
+
try:
|
162 |
+
|
163 |
+
if file_extension in ['.png', '.jpg', '.jpeg']:
|
164 |
+
image_url = file_path.replace('File:','').replace('/','')
|
165 |
+
st.write('Image URL:' + image_url)
|
166 |
+
markdown_link = f"[![Image]({image_url})]({image_url})" #file_path
|
167 |
+
st.markdown(markdown_link, unsafe_allow_html=True)
|
168 |
+
elif file_extension in ['.md', '.markdown']:
|
169 |
+
with open(file_path, "r") as file:
|
170 |
+
content = file.read()
|
171 |
+
edited_content = st.text_area(f"Edit {os.path.basename(file_path)}", value=content, height=250)
|
172 |
+
if st.button(f"Save {os.path.basename(file_path)}"):
|
173 |
+
with open(file_path, "w") as file:
|
174 |
+
file.write(edited_content)
|
175 |
+
st.success(f"Saved {os.path.basename(file_path)}!")
|
176 |
+
elif file_extension in ['.html', '.txt']:
|
177 |
+
with open(file_path, "r") as file:
|
178 |
+
st.markdown(file.read(), unsafe_allow_html=True)
|
179 |
+
#elif file_extension in ['.pdf']:
|
180 |
+
#pdf_file = open(file_path, "rb")
|
181 |
+
#base64_pdf = base64.b64encode(pdf_file.read()).decode('utf-8')
|
182 |
+
#pdf_display = f'<iframe src="data:application/pdf;base64,{base64_pdf}" width="700" height="1000" type="application/pdf"></iframe>'
|
183 |
+
#st.markdown(pdf_display, unsafe_allow_html=True)
|
184 |
+
except Exception as e:
|
185 |
+
st.error(f"Error reading file {file_path}: {e}")
|
186 |
+
|
187 |
+
|
188 |
def show_download_links(subdir):
|
189 |
global file_sequence_numbers
|
190 |
for file in list_files(subdir):
|
|
|
224 |
b64 = base64.b64encode(bytes).decode()
|
225 |
href = f'<a href="data:file/octet-stream;base64,{b64}" download=\'{os.path.basename(file)}\'>Download: {os.path.basename(file)}</a>'
|
226 |
return href
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
227 |
|
228 |
|
229 |
|