-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
78 lines (59 loc) · 2.09 KB
/
app.py
File metadata and controls
78 lines (59 loc) · 2.09 KB
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
import streamlit as st
from image_analyzer import analyze_image
st.set_page_config(page_title="Imagefier")
def speak(text):
st.components.v1.html(
f"""
<script>
const msg = new SpeechSynthesisUtterance({repr(text)});
window.speechSynthesis.cancel();
window.speechSynthesis.speak(msg);
</script>
""",
height=0,
)
if "last_result" not in st.session_state:
st.session_state.last_result = ""
st.title("Imagefier")
st.write("AI-powered image understanding for blind users")
# ---------------- Instructions ----------------
if st.button("Hear instructions"):
speak(
"Welcome to Imagefier. "
"This tool uses artificial intelligence to explain images for blind users. "
"You can upload an image or take a photo to understand what is in front of you."
)
# ---------------- Camera Mode ----------------
st.subheader("Camera Mode")
if st.button("Start camera guidance"):
speak(
"Camera mode is on. "
"Hold your phone straight in front of you at chest level. "
"Point the camera forward. "
"Keep the phone steady. "
"When ready, tap once to take the photo."
)
camera_image = st.camera_input("Take a photo")
if camera_image:
speak("Photo captured. Analyzing what is in front of you.")
with st.spinner("Analyzing image..."):
result = analyze_image(camera_image.getvalue())
st.subheader("AI Explanation")
st.write(result)
speak(result)
st.session_state.last_result = result
# ---------------- Upload Mode ----------------
st.subheader("Upload Mode")
image = st.file_uploader("Upload an image", type=["jpg", "png", "jpeg"])
if image:
speak("Image uploaded. Analyzing now.")
with st.spinner("Analyzing image..."):
result = analyze_image(image.getvalue())
st.subheader("AI Explanation")
st.write(result)
speak(result)
st.session_state.last_result = result
# ---------------- Repeat ----------------
if st.session_state.last_result:
if st.button("Repeat explanation"):
speak(st.session_state.last_result)