Spaces:
Running
Running
Update pages/4_๐ผ_text_to_Image_Search.py
Browse files
pages/4_๐ผ_text_to_Image_Search.py
CHANGED
@@ -4,58 +4,8 @@ from PIL import Image
|
|
4 |
from io import BytesIO
|
5 |
import os
|
6 |
|
7 |
-
# Set up the page with
|
8 |
st.set_page_config(page_title="Pexels Image Search", layout="wide")
|
9 |
-
|
10 |
-
# Custom CSS to maintain background
|
11 |
-
st.markdown("""
|
12 |
-
<style>
|
13 |
-
/* Main container styling */
|
14 |
-
.main .block-container {
|
15 |
-
background-color: transparent !important;
|
16 |
-
padding-top: 2rem;
|
17 |
-
}
|
18 |
-
|
19 |
-
/* Image styling */
|
20 |
-
.stImage>img {
|
21 |
-
border-radius: 8px;
|
22 |
-
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.1);
|
23 |
-
transition: transform 0.3s;
|
24 |
-
cursor: pointer;
|
25 |
-
}
|
26 |
-
.stImage>img:hover {
|
27 |
-
transform: scale(1.02);
|
28 |
-
}
|
29 |
-
|
30 |
-
/* Expander styling */
|
31 |
-
[data-testid="stExpander"] {
|
32 |
-
background-color: rgba(248, 249, 250, 0.9);
|
33 |
-
border-radius: 8px;
|
34 |
-
padding: 10px;
|
35 |
-
margin-top: 5px;
|
36 |
-
}
|
37 |
-
|
38 |
-
/* Sidebar styling - make it blend with background */
|
39 |
-
[data-testid="stSidebar"] {
|
40 |
-
background-color: rgba(248, 249, 250, 0.9) !important;
|
41 |
-
padding: 20px;
|
42 |
-
border-radius: 10px;
|
43 |
-
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.1);
|
44 |
-
}
|
45 |
-
|
46 |
-
/* Title styling */
|
47 |
-
h1, h2, h3 {
|
48 |
-
color: inherit !important;
|
49 |
-
}
|
50 |
-
|
51 |
-
/* Button styling */
|
52 |
-
.stButton>button {
|
53 |
-
width: 100%;
|
54 |
-
border: 1px solid #ddd !important;
|
55 |
-
}
|
56 |
-
</style>
|
57 |
-
""", unsafe_allow_html=True)
|
58 |
-
|
59 |
st.title("๐ท Pexels Image Search with Attribution")
|
60 |
st.write("Search for images and properly credit the photographers")
|
61 |
|
@@ -102,8 +52,8 @@ if search_query:
|
|
102 |
response = requests.get(img_url, timeout=10)
|
103 |
img = Image.open(BytesIO(response.content))
|
104 |
|
105 |
-
# Display clickable
|
106 |
-
st.image(
|
107 |
img,
|
108 |
caption=f"{photo['photographer']} - {photo['alt'][:50]}...",
|
109 |
use_container_width=True
|
@@ -143,14 +93,14 @@ if search_query:
|
|
143 |
elif results:
|
144 |
st.warning("No results found")
|
145 |
|
146 |
-
# Image details sidebar (
|
147 |
if st.session_state.selected_image:
|
148 |
photo = st.session_state.selected_image
|
149 |
with st.sidebar:
|
150 |
st.title("Image Details")
|
151 |
|
152 |
try:
|
153 |
-
img_url = photo['src']['large']
|
154 |
response = requests.get(img_url, timeout=10)
|
155 |
img = Image.open(BytesIO(response.content))
|
156 |
st.image(img, use_container_width=True)
|
@@ -178,4 +128,17 @@ if st.session_state.selected_image:
|
|
178 |
|
179 |
if st.button("Close Details", use_container_width=True):
|
180 |
st.session_state.selected_image = None
|
181 |
-
st.rerun()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
from io import BytesIO
|
5 |
import os
|
6 |
|
7 |
+
# Set up the page with default Streamlit styling
|
8 |
st.set_page_config(page_title="Pexels Image Search", layout="wide")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
st.title("๐ท Pexels Image Search with Attribution")
|
10 |
st.write("Search for images and properly credit the photographers")
|
11 |
|
|
|
52 |
response = requests.get(img_url, timeout=10)
|
53 |
img = Image.open(BytesIO(response.content))
|
54 |
|
55 |
+
# Display image with clickable option
|
56 |
+
clicked = st.image(
|
57 |
img,
|
58 |
caption=f"{photo['photographer']} - {photo['alt'][:50]}...",
|
59 |
use_container_width=True
|
|
|
93 |
elif results:
|
94 |
st.warning("No results found")
|
95 |
|
96 |
+
# Image details sidebar (using default Streamlit styling)
|
97 |
if st.session_state.selected_image:
|
98 |
photo = st.session_state.selected_image
|
99 |
with st.sidebar:
|
100 |
st.title("Image Details")
|
101 |
|
102 |
try:
|
103 |
+
img_url = photo['src']['large']
|
104 |
response = requests.get(img_url, timeout=10)
|
105 |
img = Image.open(BytesIO(response.content))
|
106 |
st.image(img, use_container_width=True)
|
|
|
128 |
|
129 |
if st.button("Close Details", use_container_width=True):
|
130 |
st.session_state.selected_image = None
|
131 |
+
st.rerun()
|
132 |
+
|
133 |
+
# Minimal styling that doesn't override defaults
|
134 |
+
st.markdown("""
|
135 |
+
<style>
|
136 |
+
.stImage>img {
|
137 |
+
border-radius: 8px;
|
138 |
+
transition: transform 0.3s;
|
139 |
+
}
|
140 |
+
.stImage>img:hover {
|
141 |
+
transform: scale(1.02);
|
142 |
+
}
|
143 |
+
</style>
|
144 |
+
""", unsafe_allow_html=True)
|