shamimjony1000 commited on
Commit
6808fed
·
verified ·
1 Parent(s): d93bc11

Update app.py

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