eagle0504 commited on
Commit
22f53cc
·
verified ·
1 Parent(s): 61d881c

Update helper.py

Browse files
Files changed (1) hide show
  1. helper.py +13 -5
helper.py CHANGED
@@ -9,17 +9,25 @@ from openai import OpenAI
9
  import streamlit as st
10
  import streamlit.components.v1 as components
11
 
12
- # Function to render custom HTML file uploader
13
  def custom_file_uploader():
14
  uploader_html = """
15
  <input type="file" id="fileUpload" accept=".png,.jpg,.jpeg" />
16
  <script>
17
- // Hide the 'Take photo' option (works on some browsers, not universally enforced)
18
- document.getElementById("fileUpload").capture = false;
 
 
 
 
 
 
 
 
 
 
19
  </script>
20
  """
21
- # Embedding custom HTML uploader
22
- components.html(uploader_html, height=100)
23
 
24
  def resize_image(image: Image.Image) -> Image.Image:
25
  new_height = int(image.height * 512 / image.width)
 
9
  import streamlit as st
10
  import streamlit.components.v1 as components
11
 
 
12
  def custom_file_uploader():
13
  uploader_html = """
14
  <input type="file" id="fileUpload" accept=".png,.jpg,.jpeg" />
15
  <script>
16
+ const fileInput = document.getElementById("fileUpload");
17
+ fileInput.addEventListener("change", function(event) {
18
+ if (fileInput.files.length > 0) {
19
+ const file = fileInput.files[0];
20
+ const reader = new FileReader();
21
+ reader.readAsDataURL(file);
22
+ reader.onload = function() {
23
+ const result = reader.result;
24
+ window.parent.postMessage({type: 'FILE_UPLOAD', file: result}, '*');
25
+ };
26
+ }
27
+ });
28
  </script>
29
  """
30
+ st.markdown(uploader_html, unsafe_allow_html=True)
 
31
 
32
  def resize_image(image: Image.Image) -> Image.Image:
33
  new_height = int(image.height * 512 / image.width)