Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,5 +1,6 @@
|
|
1 |
import streamlit as st
|
2 |
from PIL import Image
|
|
|
3 |
|
4 |
# Set page config to make the background dark blue
|
5 |
st.set_page_config(page_title="My App", layout="centered")
|
@@ -16,19 +17,45 @@ st.markdown(
|
|
16 |
unsafe_allow_html=True
|
17 |
)
|
18 |
|
19 |
-
#
|
|
|
|
|
|
|
20 |
def display_image(image_path, caption):
|
21 |
-
|
22 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
|
24 |
-
#
|
25 |
-
|
26 |
-
display_image("accuracy.jpeg", "Accuracy")
|
27 |
-
display_image("heirarchy_cluster.jpeg", "Heirarchy Cluster")
|
28 |
-
display_image("sentiment.jpeg", "Sentiment")
|
29 |
-
display_image("similarity_matrix.jpeg", "Similarity Matrix")
|
30 |
-
display_image("topic_groups.jpeg", "Topic Groups")
|
31 |
|
32 |
-
|
33 |
-
st.
|
|
|
|
|
|
|
|
|
34 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import streamlit as st
|
2 |
from PIL import Image
|
3 |
+
import os
|
4 |
|
5 |
# Set page config to make the background dark blue
|
6 |
st.set_page_config(page_title="My App", layout="centered")
|
|
|
17 |
unsafe_allow_html=True
|
18 |
)
|
19 |
|
20 |
+
# Base path for images and HTML files in the Hugging Face Spaces repository
|
21 |
+
base_path = "Karlsen/Tweet_data/"
|
22 |
+
|
23 |
+
# Define function to load and display images with error handling
|
24 |
def display_image(image_path, caption):
|
25 |
+
try:
|
26 |
+
image = Image.open(image_path)
|
27 |
+
st.image(image, caption=caption, use_column_width=True)
|
28 |
+
except FileNotFoundError:
|
29 |
+
st.error(f"File not found: {image_path}")
|
30 |
+
except Exception as e:
|
31 |
+
st.error(f"An error occurred while loading {image_path}: {e}")
|
32 |
+
|
33 |
+
# List of image files with their captions
|
34 |
+
image_files = [
|
35 |
+
("head10.jpeg", "Head 10"),
|
36 |
+
("accuracy.jpeg", "Accuracy"),
|
37 |
+
("heirarchy_cluster.jpeg", "Heirarchy Cluster"),
|
38 |
+
("sentiment.jpeg", "Sentiment"),
|
39 |
+
("similarity_matrix.jpeg", "Similarity Matrix"),
|
40 |
+
("topic_groups.jpeg", "Topic Groups")
|
41 |
+
]
|
42 |
|
43 |
+
# Check if the images are in the correct directory
|
44 |
+
missing_files = [file for file, _ in image_files if not os.path.exists(base_path + file)]
|
|
|
|
|
|
|
|
|
|
|
45 |
|
46 |
+
if missing_files:
|
47 |
+
st.error(f"Missing files: {', '.join(missing_files)}")
|
48 |
+
else:
|
49 |
+
# Display images
|
50 |
+
for file, caption in image_files:
|
51 |
+
display_image(base_path + file, caption)
|
52 |
|
53 |
+
# Display interactive HTML file with error handling
|
54 |
+
html_file = base_path + "bertopic_visualization.html"
|
55 |
+
if os.path.exists(html_file):
|
56 |
+
try:
|
57 |
+
st.components.v1.html(open(html_file, "r").read(), height=800)
|
58 |
+
except Exception as e:
|
59 |
+
st.error(f"An error occurred while loading {html_file}: {e}")
|
60 |
+
else:
|
61 |
+
st.error(f"File not found: {html_file}")
|