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
|
6 |
-
def
|
7 |
-
return
|
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:
|
@@ -89,10 +89,10 @@ if uploaded_file is not None and analyze_button:
|
|
89 |
"content": [
|
90 |
{"type": "text", "text": prompt_text},
|
91 |
{
|
92 |
-
"type": "
|
93 |
-
"
|
94 |
-
#
|
95 |
-
"
|
96 |
},
|
97 |
},
|
98 |
],
|
@@ -105,7 +105,7 @@ if uploaded_file is not None and analyze_button:
|
|
105 |
completion = client.chat.completions.create(
|
106 |
model="meta-llama/Llama-3.2-11B-Vision-Instruct",
|
107 |
messages=messages,
|
108 |
-
max_tokens=500
|
109 |
)
|
110 |
|
111 |
# Extract the assistant's response
|
|
|
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 |
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:
|
|
|
89 |
"content": [
|
90 |
{"type": "text", "text": prompt_text},
|
91 |
{
|
92 |
+
"type": "image",
|
93 |
+
"image": {
|
94 |
+
# Provide the image bytes directly
|
95 |
+
"bytes": image_bytes
|
96 |
},
|
97 |
},
|
98 |
],
|
|
|
105 |
completion = client.chat.completions.create(
|
106 |
model="meta-llama/Llama-3.2-11B-Vision-Instruct",
|
107 |
messages=messages,
|
108 |
+
max_tokens=500
|
109 |
)
|
110 |
|
111 |
# Extract the assistant's response
|