shamimjony1000 commited on
Commit
65f6621
1 Parent(s): 7486ea3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -53
app.py CHANGED
@@ -4,6 +4,7 @@ from database import Database
4
  from voice_handler import VoiceHandler
5
  from gemini_processor import GeminiProcessor
6
  from memory_handler import MemoryHandler
 
7
  import os
8
  from dotenv import load_dotenv
9
 
@@ -93,59 +94,13 @@ 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:
 
4
  from voice_handler import VoiceHandler
5
  from gemini_processor import GeminiProcessor
6
  from memory_handler import MemoryHandler
7
+ from voice_input import render_voice_input
8
  import os
9
  from dotenv import load_dotenv
10
 
 
94
 
95
  # Voice Input Tab
96
  with tab1:
97
+ render_voice_input(
98
+ voice_handler,
99
+ language_option,
100
+ language_mapping,
101
+ st.session_state.memory_handler,
102
+ gemini_processor
103
+ )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
104
 
105
  # Text Input Tab
106
  with tab2: