Spaces:
Sleeping
Sleeping
shamimjony1000
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -88,67 +88,68 @@ language_mapping = {
|
|
88 |
"Mixed (Arabic/English)": "mixed"
|
89 |
}
|
90 |
|
91 |
-
#
|
92 |
-
|
93 |
|
94 |
-
# Input
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
# Voice Input Tab
|
102 |
-
with tab1:
|
103 |
-
col1, col2, col3 = st.columns([3, 1, 1])
|
104 |
-
with col1:
|
105 |
-
if language_option == "Arabic":
|
106 |
-
st.markdown("""
|
107 |
-
جرب أن تقول شيئاً مثل:
|
108 |
-
> "أحتاج إلى طلب 500 ريال للمشروع 223 المسمى جامعة أبها لشراء بعض الأدوات"
|
109 |
-
""")
|
110 |
else:
|
111 |
-
st.
|
112 |
-
Try saying something like:
|
113 |
-
> "I need to request 500 riyals for project 223 named Abha University to buy some tools"
|
114 |
-
""")
|
115 |
-
with col2:
|
116 |
-
if st.button("🎤 Start Voice Input"):
|
117 |
-
with st.spinner("Listening... Please speak clearly"):
|
118 |
-
voice_text = voice_handler.listen_for_voice(language_mapping[language_option])
|
119 |
-
if not voice_text.startswith("Error") and not voice_text.startswith("Could not"):
|
120 |
-
st.success("Voice captured!")
|
121 |
-
st.write("You said:", voice_text)
|
122 |
-
|
123 |
-
# Add to memory
|
124 |
-
st.session_state.memory_handler.add_interaction(voice_text)
|
125 |
-
|
126 |
-
with st.spinner("Processing voice input..."):
|
127 |
-
context = st.session_state.memory_handler.get_context()
|
128 |
-
details = gemini_processor.extract_request_details(voice_text, context)
|
129 |
-
if details:
|
130 |
-
st.session_state['voice_details'] = details
|
131 |
-
if 'translated_text' in details:
|
132 |
-
st.info(f"Translated text: {details['translated_text']}")
|
133 |
-
if details.get('missing_fields'):
|
134 |
-
missing = ", ".join(details['missing_fields'])
|
135 |
-
st.warning(f"Please provide the following missing information: {missing}")
|
136 |
-
else:
|
137 |
-
st.success("Voice input processed! Please verify the details below.")
|
138 |
-
else:
|
139 |
-
st.error("Could not extract request details. Please try again or use manual input.")
|
140 |
-
else:
|
141 |
-
st.error(voice_text)
|
142 |
-
with col3:
|
143 |
-
if st.button("🗑️ Clear Memory"):
|
144 |
-
st.session_state.memory_handler.clear_memory()
|
145 |
-
if 'voice_details' in st.session_state:
|
146 |
-
del st.session_state['voice_details']
|
147 |
-
st.success("Memory cleared!")
|
148 |
|
149 |
-
|
150 |
-
with
|
151 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
152 |
|
153 |
# Show conversation history
|
154 |
if st.session_state.memory_handler.conversation_history:
|
|
|
88 |
"Mixed (Arabic/English)": "mixed"
|
89 |
}
|
90 |
|
91 |
+
# Input Method Tabs
|
92 |
+
tab1, tab2 = st.tabs(["Voice Input", "Text Input"])
|
93 |
|
94 |
+
# Voice Input Tab
|
95 |
+
with tab1:
|
96 |
+
if not voice_handler.permission_granted:
|
97 |
+
st.info("Please grant microphone permissions when prompted to use voice input.")
|
98 |
+
if st.button("Request Microphone Access"):
|
99 |
+
if voice_handler.request_permissions():
|
100 |
+
st.success("Microphone access granted!")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
101 |
else:
|
102 |
+
st.error("Could not access microphone. Please check your browser settings.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
103 |
|
104 |
+
col1, col2, col3 = st.columns([3, 1, 1])
|
105 |
+
with col1:
|
106 |
+
if language_option == "Arabic":
|
107 |
+
st.markdown("""
|
108 |
+
جرب أن تقول شيئاً مثل:
|
109 |
+
> "أحتاج إلى طلب 500 ريال للمشروع 223 المسمى جامعة أبها لشراء بعض الأدوات"
|
110 |
+
""")
|
111 |
+
else:
|
112 |
+
st.markdown("""
|
113 |
+
Try saying something like:
|
114 |
+
> "I need to request 500 riyals for project 223 named Abha University to buy some tools"
|
115 |
+
""")
|
116 |
+
with col2:
|
117 |
+
if st.button("🎤 Start Voice Input"):
|
118 |
+
with st.spinner("Listening... Please speak clearly"):
|
119 |
+
voice_text = voice_handler.listen_for_voice(language_mapping[language_option])
|
120 |
+
if not voice_text.startswith("Error") and not voice_text.startswith("Could not"):
|
121 |
+
st.success("Voice captured!")
|
122 |
+
st.write("You said:", voice_text)
|
123 |
+
|
124 |
+
# Add to memory
|
125 |
+
st.session_state.memory_handler.add_interaction(voice_text)
|
126 |
+
|
127 |
+
with st.spinner("Processing voice input..."):
|
128 |
+
context = st.session_state.memory_handler.get_context()
|
129 |
+
details = gemini_processor.extract_request_details(voice_text, context)
|
130 |
+
if details:
|
131 |
+
st.session_state['voice_details'] = details
|
132 |
+
if 'translated_text' in details:
|
133 |
+
st.info(f"Translated text: {details['translated_text']}")
|
134 |
+
if details.get('missing_fields'):
|
135 |
+
missing = ", ".join(details['missing_fields'])
|
136 |
+
st.warning(f"Please provide the following missing information: {missing}")
|
137 |
+
else:
|
138 |
+
st.success("Voice input processed! Please verify the details below.")
|
139 |
+
else:
|
140 |
+
st.error("Could not extract request details. Please try again or use manual input.")
|
141 |
+
else:
|
142 |
+
st.error(voice_text)
|
143 |
+
with col3:
|
144 |
+
if st.button("🗑️ Clear Memory"):
|
145 |
+
st.session_state.memory_handler.clear_memory()
|
146 |
+
if 'voice_details' in st.session_state:
|
147 |
+
del st.session_state['voice_details']
|
148 |
+
st.success("Memory cleared!")
|
149 |
+
|
150 |
+
# Text Input Tab
|
151 |
+
with tab2:
|
152 |
+
render_text_input(language_option)
|
153 |
|
154 |
# Show conversation history
|
155 |
if st.session_state.memory_handler.conversation_history:
|