Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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
|
| 6 |
-
def
|
| 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 |
-
#
|
| 67 |
-
|
| 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
|
| 95 |
-
"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 |
],
|