Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -316,48 +316,36 @@ FileSidebar()
|
|
316 |
|
317 |
|
318 |
|
319 |
-
|
320 |
-
|
321 |
-
|
322 |
-
response = requests.get(url)
|
323 |
-
if response.status_code == 200:
|
324 |
-
# Convert the image to base64
|
325 |
-
return base64.b64encode(response.content).decode("utf-8")
|
326 |
-
else:
|
327 |
-
return None
|
328 |
|
329 |
-
|
330 |
-
|
331 |
-
|
|
|
|
|
|
|
|
|
|
|
332 |
|
333 |
-
#
|
334 |
-
|
335 |
-
"https://cdn-uploads.huggingface.co/production/uploads/620630b603825909dcbeba35/W1omJItftG3OkW9sj-Ckb.png",
|
336 |
-
"https://cdn-uploads.huggingface.co/production/uploads/620630b603825909dcbeba35/Djx-k4WOxzlXEQPzllP3r.png"
|
337 |
-
]
|
338 |
|
339 |
-
# Select a random
|
340 |
-
|
341 |
|
342 |
-
#
|
343 |
-
st.write(selected_image_url)
|
344 |
try:
|
345 |
-
|
346 |
-
|
347 |
-
if selected_image_base64 is not None:
|
348 |
with st.sidebar:
|
349 |
st.markdown("""### Graphic Novel AI""")
|
350 |
-
|
351 |
-
st.markdown(f"![image](data:image/png;base64,{selected_image_base64})")
|
352 |
-
|
353 |
-
# Create and display the download link
|
354 |
-
download_link = create_download_link("downloaded_image.png", selected_image_base64)
|
355 |
-
st.markdown(download_link, unsafe_allow_html=True)
|
356 |
else:
|
357 |
-
st.sidebar.write("
|
358 |
-
except:
|
359 |
-
st.write('Sidebar Fail - Check your Images')
|
360 |
-
|
361 |
|
362 |
|
363 |
|
|
|
316 |
|
317 |
|
318 |
|
319 |
+
import streamlit as st
|
320 |
+
import random
|
321 |
+
import os
|
|
|
|
|
|
|
|
|
|
|
|
|
322 |
|
323 |
+
# Function to get a list of image paths from the /images directory
|
324 |
+
def get_image_paths(directory="/images"):
|
325 |
+
image_paths = [os.path.join(directory, file) for file in os.listdir(directory) if file.endswith(('png', 'jpg', 'jpeg'))]
|
326 |
+
return image_paths
|
327 |
+
|
328 |
+
# Function to select a random image path
|
329 |
+
def select_random_image_path(image_paths):
|
330 |
+
return random.choice(image_paths)
|
331 |
|
332 |
+
# Get list of image paths from the /images directory
|
333 |
+
image_paths = get_image_paths()
|
|
|
|
|
|
|
334 |
|
335 |
+
# Select a random image path from the list
|
336 |
+
selected_image_path = select_random_image_path(image_paths)
|
337 |
|
338 |
+
# Display the selected image in the sidebar
|
|
|
339 |
try:
|
340 |
+
if selected_image_path:
|
|
|
|
|
341 |
with st.sidebar:
|
342 |
st.markdown("""### Graphic Novel AI""")
|
343 |
+
st.image(selected_image_path, caption=selected_image_path)
|
|
|
|
|
|
|
|
|
|
|
344 |
else:
|
345 |
+
st.sidebar.write("No images found in the directory.")
|
346 |
+
except Exception as e:
|
347 |
+
st.write(f'Sidebar Fail - Check your Images. Error: {e}')
|
348 |
+
|
349 |
|
350 |
|
351 |
|