Spaces:
Sleeping
Sleeping
File size: 3,183 Bytes
4fa40c3 c02e95c 4fa40c3 7fb2e59 c02e95c d68f001 7fb2e59 2d29a6e 7fb2e59 d68f001 c02e95c 7fb2e59 c02e95c 7fb2e59 c02e95c 7fb2e59 e12e90b 7fb2e59 e12e90b 7fb2e59 662677a 2d29a6e 662677a 2d29a6e 662677a 2d29a6e 7fb2e59 2d29a6e 7fb2e59 2d29a6e 7fb2e59 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
import streamlit as st
import requests
import base64
# Function to encode image in base64
def encode_image(image):
return base64.b64encode(image.read()).decode('utf-8')
# Function to send data to the GPT-4 Vision API
def analyze_images(images, use_case, api_key):
headers = {"Authorization": f"Bearer {api_key}", "Content-Type": "application/json"}
prompt_text = (
f"This is a prototype for {use_case}.\n"
"Review each screenshot carefully, focusing on different aspects of usability.\n"
"Evaluate each screenshot based on Nielsen's 10 usability heuristics:\n"
"- Visibility of system status\n"
"- Match between system and the real world\n"
"- User control and freedom\n"
"- Consistency and standards\n"
"- Error prevention\n"
"- Recognition rather than recall\n"
"- Flexibility and efficiency of use\n"
"- Aesthetic and minimalist design\n"
"- Help users recognize, diagnose, and recover from errors\n"
"- Help and documentation\n"
"Create a table with the following columns:\n"
"Heuristic evaluated, Comments (Provide specific observations and suggestions for improvement)"
)
messages_content = [
{
"role": "user",
"content": [
{"type": "text", "text": prompt_text}
]
}
]
for image in images:
base64_image = encode_image(image)
messages_content[0]["content"].append({
"type": "image_url",
"image_url": {"url": f"data:image/jpeg;base64,{base64_image}"}
})
data = {
"model": "gpt-4-turbo",
"messages": messages_content,
"max_tokens": 1024 # Adjusted max_tokens to give more room for detailed analysis
}
response = requests.post("https://api.openai.com/v1/chat/completions", headers=headers, json=data)
return response.json()
# Streamlit UI setup
st.title("Auto Heuristic Evaluation")
uploaded_files = st.file_uploader("Upload images (up to 5)", accept_multiple_files=True, type=['jpg', 'jpeg', 'png'])
use_case = st.text_input("Use Case - Describe the use case for your prototype")
api_key = st.text_input("OpenAI API Key", type="password")
if st.button("Analyze Images"):
if not uploaded_files:
st.warning("Please upload at least one image.")
elif not use_case:
st.warning("Please enter the use case description.")
elif not api_key:
st.warning("Please enter the OpenAI API key.")
else:
with st.spinner("Analyzing images..."):
analysis_result = analyze_images(uploaded_files, use_case, api_key)
if 'error' in analysis_result:
st.error(f"Analysis failed: {analysis_result.get('error', {}).get('message', 'Unknown error')}")
else:
st.success("Analysis complete!")
if 'choices' in analysis_result and analysis_result['choices']:
content = analysis_result['choices'][0]['message']['content']
st.markdown(content)
else:
st.warning("No detailed results available.")
|