Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -17,6 +17,51 @@ st.set_page_config(
|
|
| 17 |
}
|
| 18 |
)
|
| 19 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
# Ensure the directory for storing scores exists
|
| 21 |
score_dir = "scores"
|
| 22 |
os.makedirs(score_dir, exist_ok=True)
|
|
|
|
| 17 |
}
|
| 18 |
)
|
| 19 |
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
import base64
|
| 25 |
+
import requests
|
| 26 |
+
|
| 27 |
+
# Function to fetch and encode the image to base64
|
| 28 |
+
def get_image_as_base64(url):
|
| 29 |
+
response = requests.get(url)
|
| 30 |
+
if response.status_code == 200:
|
| 31 |
+
# Convert the image to base64
|
| 32 |
+
return base64.b64encode(response.content).decode("utf-8")
|
| 33 |
+
else:
|
| 34 |
+
return None
|
| 35 |
+
|
| 36 |
+
# Function to create a download link for the image
|
| 37 |
+
def create_download_link(filename, base64_str):
|
| 38 |
+
href = f'<a href="data:file/png;base64,{base64_str}" download="{filename}">Download Image</a>'
|
| 39 |
+
return href
|
| 40 |
+
|
| 41 |
+
# URL of the image you want to display and download
|
| 42 |
+
image_url = "https://cdn-uploads.huggingface.co/production/uploads/620630b603825909dcbeba35/pxbIhDGTbdgv22giGuI-i.png"
|
| 43 |
+
image_base64 = get_image_as_base64(image_url)
|
| 44 |
+
|
| 45 |
+
if image_base64 is not None:
|
| 46 |
+
# Display the image using the base64 string
|
| 47 |
+
with st.sidebar:
|
| 48 |
+
st.markdown(f"")
|
| 49 |
+
|
| 50 |
+
# Provide a download link for the image
|
| 51 |
+
download_link = create_download_link("downloaded_image.png", image_base64)
|
| 52 |
+
st.markdown(download_link, unsafe_allow_html=True)
|
| 53 |
+
else:
|
| 54 |
+
st.sidebar.write("Failed to load the image.")
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
with st.sidebar:
|
| 58 |
+
st.markdown("""
|
| 59 |
+
### Mixable Card Game AI
|
| 60 |
+
|
| 61 |
+
""")
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
|
| 65 |
# Ensure the directory for storing scores exists
|
| 66 |
score_dir = "scores"
|
| 67 |
os.makedirs(score_dir, exist_ok=True)
|