Update app.py
Browse files
app.py
CHANGED
|
@@ -9,6 +9,7 @@ import json
|
|
| 9 |
import uuid
|
| 10 |
import glob
|
| 11 |
import zipfile
|
|
|
|
| 12 |
|
| 13 |
EXCLUDED_FILES = ['app.py', 'requirements.txt', 'pre-requirements.txt', 'packages.txt', 'README.md','.gitattributes', "backup.py","Dockerfile"]
|
| 14 |
URLS = {
|
|
@@ -197,11 +198,29 @@ def get_download_link(file):
|
|
| 197 |
return href
|
| 198 |
|
| 199 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 200 |
def show_file_content(file_path):
|
| 201 |
_, file_extension = os.path.splitext(file_path)
|
| 202 |
try:
|
| 203 |
if file_extension in ['.png', '.jpg', '.jpeg']:
|
| 204 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 205 |
elif file_extension in ['.md', '.markdown']:
|
| 206 |
with open(file_path, "r") as file:
|
| 207 |
content = file.read()
|
|
|
|
| 9 |
import uuid
|
| 10 |
import glob
|
| 11 |
import zipfile
|
| 12 |
+
from PIL import Image
|
| 13 |
|
| 14 |
EXCLUDED_FILES = ['app.py', 'requirements.txt', 'pre-requirements.txt', 'packages.txt', 'README.md','.gitattributes', "backup.py","Dockerfile"]
|
| 15 |
URLS = {
|
|
|
|
| 198 |
return href
|
| 199 |
|
| 200 |
|
| 201 |
+
def show_file_content_new_style(file_path):
|
| 202 |
+
_, file_extension = os.path.splitext(file_path)
|
| 203 |
+
try:
|
| 204 |
+
if file_extension in ['.png', '.jpg', '.jpeg']:
|
| 205 |
+
with open(file_path, "rb") as file:
|
| 206 |
+
img = Image.open(file)
|
| 207 |
+
st.image(img, caption=os.path.basename(file_path))
|
| 208 |
+
elif file_extension in ['.md', '.markdown']:
|
| 209 |
+
# ... [Markdown file handling code]
|
| 210 |
+
elif file_extension in ['.html', '.txt']:
|
| 211 |
+
# ... [HTML/Text file handling code]
|
| 212 |
+
except Exception as e:
|
| 213 |
+
st.error(f"Error reading file {file_path}: {e}")
|
| 214 |
+
|
| 215 |
def show_file_content(file_path):
|
| 216 |
_, file_extension = os.path.splitext(file_path)
|
| 217 |
try:
|
| 218 |
if file_extension in ['.png', '.jpg', '.jpeg']:
|
| 219 |
+
with open(file_path, "rb") as file:
|
| 220 |
+
img = Image.open(file)
|
| 221 |
+
st.image(img, caption=os.path.basename(file_path))
|
| 222 |
+
#if file_extension in ['.png', '.jpg', '.jpeg']:
|
| 223 |
+
# st.image(file_path)
|
| 224 |
elif file_extension in ['.md', '.markdown']:
|
| 225 |
with open(file_path, "r") as file:
|
| 226 |
content = file.read()
|