Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -2,11 +2,44 @@ import streamlit as st
|
|
2 |
import pandas as pd
|
3 |
from io import StringIO
|
4 |
|
5 |
-
st
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
|
7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
|
9 |
-
|
|
|
|
|
|
|
|
|
10 |
|
11 |
|
12 |
# Sample data for the inline CSV
|
|
|
2 |
import pandas as pd
|
3 |
from io import StringIO
|
4 |
|
5 |
+
import streamlit as st
|
6 |
+
import base64
|
7 |
+
import requests
|
8 |
+
|
9 |
+
# Function to fetch and encode the image to base64
|
10 |
+
def get_image_as_base64(url):
|
11 |
+
response = requests.get(url)
|
12 |
+
if response.status_code == 200:
|
13 |
+
# Convert the image to base64
|
14 |
+
return base64.b64encode(response.content).decode("utf-8")
|
15 |
+
else:
|
16 |
+
return None
|
17 |
+
|
18 |
+
# Function to create a download link for the image
|
19 |
+
def create_download_link(filename, base64_str):
|
20 |
+
href = f'<a href="data:file/png;base64,{base64_str}" download="{filename}">Download Image</a>'
|
21 |
+
return href
|
22 |
+
|
23 |
+
# URL of the image you want to display and download
|
24 |
+
image_url = "https://cdn-uploads.huggingface.co/production/uploads/620630b603825909dcbeba35/AswjRkg3QMR503fAScTrV.png"
|
25 |
+
image_base64 = get_image_as_base64(image_url)
|
26 |
|
27 |
+
if image_base64 is not None:
|
28 |
+
# Display the image using the base64 string
|
29 |
+
with st.sidebar:
|
30 |
+
st.markdown(f"")
|
31 |
+
|
32 |
+
# Provide a download link for the image
|
33 |
+
download_link = create_download_link("downloaded_image.png", image_base64)
|
34 |
+
st.markdown(download_link, unsafe_allow_html=True)
|
35 |
+
else:
|
36 |
+
st.sidebar.write("Failed to load the image.")
|
37 |
|
38 |
+
|
39 |
+
with st.sidebar:
|
40 |
+
st.markdown("""
|
41 |
+

|
42 |
+
""")
|
43 |
|
44 |
|
45 |
# Sample data for the inline CSV
|