Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -31,20 +31,6 @@ with st.expander("Help / About 📚", expanded=False):
|
|
| 31 |
|
| 32 |
|
| 33 |
# -----------------------------------------------------------------Art Card Sidebar:
|
| 34 |
-
import base64
|
| 35 |
-
import requests
|
| 36 |
-
def get_image_as_base64(url):
|
| 37 |
-
response = requests.get(url)
|
| 38 |
-
if response.status_code == 200:
|
| 39 |
-
# Convert the image to base64
|
| 40 |
-
return base64.b64encode(response.content).decode("utf-8")
|
| 41 |
-
else:
|
| 42 |
-
return None
|
| 43 |
-
|
| 44 |
-
def create_download_link(filename, base64_str):
|
| 45 |
-
href = f'<a href="data:file/png;base64,{base64_str}" download="{filename}">Download Image</a>'
|
| 46 |
-
return href
|
| 47 |
-
|
| 48 |
# Get this from paste into markdown feature
|
| 49 |
#image_url = "https://cdn-uploads.huggingface.co/production/uploads/620630b603825909dcbeba35/G_GkRD_IT3f14K7gWlbwi.png"
|
| 50 |
image_url2 = "https://cdn-uploads.huggingface.co/production/uploads/620630b603825909dcbeba35/gikaT871Mm8k6wuv4pl_g.png"
|
|
@@ -54,27 +40,74 @@ image_url4 = "https://cdn-uploads.huggingface.co/production/uploads/620630b60382
|
|
| 54 |
#image_url6 = "https://cdn-uploads.huggingface.co/production/uploads/620630b603825909dcbeba35/2-KfxcuXRcTFiHf4XlNsX.png"
|
| 55 |
|
| 56 |
#image_base64 = get_image_as_base64(image_url)
|
| 57 |
-
image_base642 = get_image_as_base64(image_url2)
|
| 58 |
-
image_base643 = get_image_as_base64(image_url3)
|
| 59 |
-
image_base644 = get_image_as_base64(image_url4)
|
| 60 |
#image_base645 = get_image_as_base64(image_url5)
|
| 61 |
#image_base646 = get_image_as_base64(image_url6)
|
| 62 |
|
| 63 |
-
if image_base644 is not None:
|
| 64 |
-
with st.sidebar:
|
| 65 |
-
st.markdown("""### Word Game AI""")
|
| 66 |
#st.markdown(f"")
|
| 67 |
-
st.markdown(f"")
|
| 68 |
-
st.markdown(f"")
|
| 69 |
-
st.markdown(f"")
|
| 70 |
#st.markdown(f"")
|
| 71 |
#st.markdown(f"")
|
| 72 |
#download_link = create_download_link("downloaded_image.png", image_base64)
|
| 73 |
#st.markdown(download_link, unsafe_allow_html=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 74 |
else:
|
| 75 |
st.sidebar.write("Failed to load the image.")
|
| 76 |
-
#
|
|
|
|
| 77 |
|
|
|
|
|
|
|
| 78 |
|
| 79 |
# Ensure the directory for storing scores exists
|
| 80 |
score_dir = "scores"
|
|
|
|
| 31 |
|
| 32 |
|
| 33 |
# -----------------------------------------------------------------Art Card Sidebar:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
# Get this from paste into markdown feature
|
| 35 |
#image_url = "https://cdn-uploads.huggingface.co/production/uploads/620630b603825909dcbeba35/G_GkRD_IT3f14K7gWlbwi.png"
|
| 36 |
image_url2 = "https://cdn-uploads.huggingface.co/production/uploads/620630b603825909dcbeba35/gikaT871Mm8k6wuv4pl_g.png"
|
|
|
|
| 40 |
#image_url6 = "https://cdn-uploads.huggingface.co/production/uploads/620630b603825909dcbeba35/2-KfxcuXRcTFiHf4XlNsX.png"
|
| 41 |
|
| 42 |
#image_base64 = get_image_as_base64(image_url)
|
| 43 |
+
#image_base642 = get_image_as_base64(image_url2)
|
| 44 |
+
#image_base643 = get_image_as_base64(image_url3)
|
| 45 |
+
#image_base644 = get_image_as_base64(image_url4)
|
| 46 |
#image_base645 = get_image_as_base64(image_url5)
|
| 47 |
#image_base646 = get_image_as_base64(image_url6)
|
| 48 |
|
| 49 |
+
#if image_base644 is not None:
|
| 50 |
+
# with st.sidebar:
|
| 51 |
+
# st.markdown("""### Word Game AI""")
|
| 52 |
#st.markdown(f"")
|
| 53 |
+
# st.markdown(f"")
|
| 54 |
+
# st.markdown(f"")
|
| 55 |
+
# st.markdown(f"")
|
| 56 |
#st.markdown(f"")
|
| 57 |
#st.markdown(f"")
|
| 58 |
#download_link = create_download_link("downloaded_image.png", image_base64)
|
| 59 |
#st.markdown(download_link, unsafe_allow_html=True)
|
| 60 |
+
#else:
|
| 61 |
+
# st.sidebar.write("Failed to load the image.")
|
| 62 |
+
# ------------------------------------------------------------- Art Card Sidebar
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
# ---- Art Card Sidebar with random selection of image:
|
| 67 |
+
def get_image_as_base64(url):
|
| 68 |
+
response = requests.get(url)
|
| 69 |
+
if response.status_code == 200:
|
| 70 |
+
# Convert the image to base64
|
| 71 |
+
return base64.b64encode(response.content).decode("utf-8")
|
| 72 |
+
else:
|
| 73 |
+
return None
|
| 74 |
+
|
| 75 |
+
def create_download_link(filename, base64_str):
|
| 76 |
+
href = f'<a href="data:file/png;base64,{base64_str}" download="{filename}">Download Image</a>'
|
| 77 |
+
return href
|
| 78 |
+
|
| 79 |
+
# List of image URLs
|
| 80 |
+
image_urls = [
|
| 81 |
+
"https://cdn-uploads.huggingface.co/production/uploads/620630b603825909dcbeba35/gikaT871Mm8k6wuv4pl_g.png",
|
| 82 |
+
"https://cdn-uploads.huggingface.co/production/uploads/620630b603825909dcbeba35/gv1xmIiXh1NGTeeV-cYF2.png",
|
| 83 |
+
"https://cdn-uploads.huggingface.co/production/uploads/620630b603825909dcbeba35/2YsnDyc_nDNW71PPKozdN.png",
|
| 84 |
+
"https://cdn-uploads.huggingface.co/production/uploads/620630b603825909dcbeba35/G_GkRD_IT3f14K7gWlbwi.png",
|
| 85 |
+
"https://cdn-uploads.huggingface.co/production/uploads/620630b603825909dcbeba35/eGii5DvGIuCtWCU08_i-D.png",
|
| 86 |
+
"https://cdn-uploads.huggingface.co/production/uploads/620630b603825909dcbeba35/2-KfxcuXRcTFiHf4XlNsX.png"
|
| 87 |
+
]
|
| 88 |
+
|
| 89 |
+
# Select a random URL from the list
|
| 90 |
+
selected_image_url = random.choice(image_urls)
|
| 91 |
+
|
| 92 |
+
# Get the base64 encoded string of the selected image
|
| 93 |
+
selected_image_base64 = get_image_as_base64(selected_image_url)
|
| 94 |
+
|
| 95 |
+
if selected_image_base64 is not None:
|
| 96 |
+
with st.sidebar:
|
| 97 |
+
st.markdown("""### Word Game AI""")
|
| 98 |
+
# Display the image
|
| 99 |
+
st.markdown(f"")
|
| 100 |
+
|
| 101 |
+
# Create and display the download link
|
| 102 |
+
download_link = create_download_link("downloaded_image.png", selected_image_base64)
|
| 103 |
+
st.markdown(download_link, unsafe_allow_html=True)
|
| 104 |
else:
|
| 105 |
st.sidebar.write("Failed to load the image.")
|
| 106 |
+
# ---- Art Card Sidebar with random selection of image.
|
| 107 |
+
|
| 108 |
|
| 109 |
+
|
| 110 |
+
|
| 111 |
|
| 112 |
# Ensure the directory for storing scores exists
|
| 113 |
score_dir = "scores"
|