Spaces:
Sleeping
Sleeping
shamimjony1000
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -52,59 +52,68 @@ language_mapping = {
|
|
52 |
"Mixed (Arabic/English)": "mixed"
|
53 |
}
|
54 |
|
|
|
|
|
|
|
55 |
# Input Method Tabs
|
56 |
-
|
|
|
|
|
|
|
|
|
|
|
57 |
|
58 |
# Voice Input Tab
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
|
|
|
|
|
|
93 |
else:
|
94 |
-
st.
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
del st.session_state['voice_details']
|
104 |
-
st.success("Memory cleared!")
|
105 |
|
106 |
# Text Input Tab
|
107 |
-
with tab2:
|
108 |
if language_option == "Arabic":
|
109 |
st.markdown("""
|
110 |
أدخل طلبك في شكل نص. مثال:
|
|
|
52 |
"Mixed (Arabic/English)": "mixed"
|
53 |
}
|
54 |
|
55 |
+
# Check if running in cloud environment
|
56 |
+
is_cloud = voice_handler.is_cloud
|
57 |
+
|
58 |
# Input Method Tabs
|
59 |
+
if not is_cloud:
|
60 |
+
tab1, tab2 = st.tabs(["Voice Input", "Text Input"])
|
61 |
+
current_tab = tab1
|
62 |
+
else:
|
63 |
+
st.warning("Voice input is not available in cloud deployment. Using text input only.")
|
64 |
+
current_tab = st
|
65 |
|
66 |
# Voice Input Tab
|
67 |
+
if not is_cloud:
|
68 |
+
with tab1:
|
69 |
+
col1, col2, col3 = st.columns([3, 1, 1])
|
70 |
+
with col1:
|
71 |
+
if language_option == "Arabic":
|
72 |
+
st.markdown("""
|
73 |
+
جرب أن تقول شيئاً مثل:
|
74 |
+
> "أحتاج إلى طلب 500 ريال للمشروع 223 المسمى جامعة أبها لشراء بعض الأدوات"
|
75 |
+
""")
|
76 |
+
else:
|
77 |
+
st.markdown("""
|
78 |
+
Try saying something like:
|
79 |
+
> "I need to request 500 riyals for project 223 named Abha University to buy some tools"
|
80 |
+
""")
|
81 |
+
with col2:
|
82 |
+
if st.button("🎤 Start Voice Input"):
|
83 |
+
with st.spinner("Listening... Please speak clearly"):
|
84 |
+
voice_text = voice_handler.listen_for_voice(language_mapping[language_option])
|
85 |
+
if not voice_text.startswith("Error") and not voice_text.startswith("Could not"):
|
86 |
+
st.success("Voice captured!")
|
87 |
+
st.write("You said:", voice_text)
|
88 |
+
|
89 |
+
# Add to memory
|
90 |
+
st.session_state.memory_handler.add_interaction(voice_text)
|
91 |
+
|
92 |
+
with st.spinner("Processing voice input..."):
|
93 |
+
context = st.session_state.memory_handler.get_context()
|
94 |
+
details = gemini_processor.extract_request_details(voice_text, context)
|
95 |
+
if details:
|
96 |
+
st.session_state['voice_details'] = details
|
97 |
+
if 'translated_text' in details:
|
98 |
+
st.info(f"Translated text: {details['translated_text']}")
|
99 |
+
if details.get('missing_fields'):
|
100 |
+
missing = ", ".join(details['missing_fields'])
|
101 |
+
st.warning(f"Please provide the following missing information: {missing}")
|
102 |
+
else:
|
103 |
+
st.success("Voice input processed! Please verify the details below.")
|
104 |
else:
|
105 |
+
st.error("Could not extract request details. Please try again or use manual input.")
|
106 |
+
else:
|
107 |
+
st.error(voice_text)
|
108 |
+
with col3:
|
109 |
+
if st.button("🗑️ Clear Memory"):
|
110 |
+
st.session_state.memory_handler.clear_memory()
|
111 |
+
if 'voice_details' in st.session_state:
|
112 |
+
del st.session_state['voice_details']
|
113 |
+
st.success("Memory cleared!")
|
|
|
|
|
114 |
|
115 |
# Text Input Tab
|
116 |
+
with current_tab if is_cloud else tab2:
|
117 |
if language_option == "Arabic":
|
118 |
st.markdown("""
|
119 |
أدخل طلبك في شكل نص. مثال:
|