ProfessorLeVesseur commited on
Commit
1cc3f83
·
verified ·
1 Parent(s): a293fc1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -7
app.py CHANGED
@@ -2,9 +2,9 @@ import streamlit as st
2
  import base64
3
  from huggingface_hub import InferenceClient
4
 
5
- # Function to read the image file as bytes
6
- def get_image_bytes(image_file):
7
- return image_file.read()
8
 
9
  # Streamlit page setup
10
  st.set_page_config(page_title="MTSS Image Accessibility Alt Text Generator", layout="centered", initial_sidebar_state="auto")
@@ -63,8 +63,8 @@ complex_image_prompt_text = (
63
  if uploaded_file is not None and analyze_button:
64
 
65
  with st.spinner("Analyzing the image ..."):
66
- # Read the image bytes
67
- image_bytes = get_image_bytes(uploaded_file)
68
 
69
  # Determine which prompt to use based on the complexity of the image
70
  if complex_image:
@@ -91,8 +91,8 @@ if uploaded_file is not None and analyze_button:
91
  {
92
  "type": "image",
93
  "image": {
94
- # Provide the image bytes directly
95
- "bytes": image_bytes
96
  },
97
  },
98
  ],
 
2
  import base64
3
  from huggingface_hub import InferenceClient
4
 
5
+ # Function to read the image file and return a base64-encoded string
6
+ def get_image_base64(image_file):
7
+ return base64.b64encode(image_file.read()).decode('utf-8')
8
 
9
  # Streamlit page setup
10
  st.set_page_config(page_title="MTSS Image Accessibility Alt Text Generator", layout="centered", initial_sidebar_state="auto")
 
63
  if uploaded_file is not None and analyze_button:
64
 
65
  with st.spinner("Analyzing the image ..."):
66
+ # Get base64-encoded image string
67
+ base64_image_string = get_image_base64(uploaded_file)
68
 
69
  # Determine which prompt to use based on the complexity of the image
70
  if complex_image:
 
91
  {
92
  "type": "image",
93
  "image": {
94
+ # Provide the base64-encoded image string
95
+ "bytes": base64_image_string
96
  },
97
  },
98
  ],