awacke1 commited on
Commit
3751249
1 Parent(s): f272e32

Update app.py

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