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