Spaces:
Sleeping
Sleeping
shamimjony1000
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -30,6 +30,42 @@ def validate_request(project_number, project_name, amount, reason):
|
|
30 |
return False, f"Please provide the following missing information: {', '.join(missing_fields)}"
|
31 |
return True, ""
|
32 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
st.title("AI Agent Money Request System")
|
34 |
st.markdown("---")
|
35 |
|
@@ -55,16 +91,14 @@ language_mapping = {
|
|
55 |
# Check if running in cloud environment
|
56 |
is_cloud = voice_handler.is_cloud
|
57 |
|
58 |
-
# Input Method
|
59 |
-
if
|
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 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
|
|
68 |
with tab1:
|
69 |
col1, col2, col3 = st.columns([3, 1, 1])
|
70 |
with col1:
|
@@ -111,42 +145,10 @@ if not is_cloud:
|
|
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 |
-
أدخل طلبك في شكل نص. مثال:
|
120 |
-
> "أحتاج إلى طلب 500 ريال للمشروع 223 المسمى جامعة أبها لشراء بعض الأدوات"
|
121 |
-
""")
|
122 |
-
else:
|
123 |
-
st.markdown("""
|
124 |
-
Enter your request in text format. Example:
|
125 |
-
> "I need to request 500 riyals for project 223 named Abha University to buy some tools"
|
126 |
-
""")
|
127 |
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
with col1:
|
132 |
-
if st.button("Process Text"):
|
133 |
-
if text_input:
|
134 |
-
with st.spinner("Processing text input..."):
|
135 |
-
context = st.session_state.memory_handler.get_context()
|
136 |
-
details = gemini_processor.extract_request_details(text_input, context)
|
137 |
-
if details:
|
138 |
-
st.session_state['voice_details'] = details
|
139 |
-
if 'translated_text' in details:
|
140 |
-
st.info(f"Translated text: {details['translated_text']}")
|
141 |
-
if details.get('missing_fields'):
|
142 |
-
missing = ", ".join(details['missing_fields'])
|
143 |
-
st.warning(f"Please provide the following missing information: {missing}")
|
144 |
-
else:
|
145 |
-
st.success("Text processed! Please verify the details below.")
|
146 |
-
else:
|
147 |
-
st.error("Could not extract request details. Please try again.")
|
148 |
-
else:
|
149 |
-
st.warning("Please enter some text first.")
|
150 |
|
151 |
# Show conversation history
|
152 |
if st.session_state.memory_handler.conversation_history:
|
|
|
30 |
return False, f"Please provide the following missing information: {', '.join(missing_fields)}"
|
31 |
return True, ""
|
32 |
|
33 |
+
def render_text_input(language_option):
|
34 |
+
"""Render the text input section"""
|
35 |
+
if language_option == "Arabic":
|
36 |
+
st.markdown("""
|
37 |
+
أدخل طلبك في شكل نص. مثال:
|
38 |
+
> "أحتاج إلى طلب 500 ريال للمشروع 223 المسمى جامعة أبها لشراء بعض الأدوات"
|
39 |
+
""")
|
40 |
+
else:
|
41 |
+
st.markdown("""
|
42 |
+
Enter your request in text format. Example:
|
43 |
+
> "I need to request 500 riyals for project 223 named Abha University to buy some tools"
|
44 |
+
""")
|
45 |
+
|
46 |
+
text_input = st.text_area("Enter your request:", height=100)
|
47 |
+
col1, col2 = st.columns([1, 4])
|
48 |
+
|
49 |
+
with col1:
|
50 |
+
if st.button("Process Text"):
|
51 |
+
if text_input:
|
52 |
+
with st.spinner("Processing text input..."):
|
53 |
+
context = st.session_state.memory_handler.get_context()
|
54 |
+
details = gemini_processor.extract_request_details(text_input, context)
|
55 |
+
if details:
|
56 |
+
st.session_state['voice_details'] = details
|
57 |
+
if 'translated_text' in details:
|
58 |
+
st.info(f"Translated text: {details['translated_text']}")
|
59 |
+
if details.get('missing_fields'):
|
60 |
+
missing = ", ".join(details['missing_fields'])
|
61 |
+
st.warning(f"Please provide the following missing information: {missing}")
|
62 |
+
else:
|
63 |
+
st.success("Text processed! Please verify the details below.")
|
64 |
+
else:
|
65 |
+
st.error("Could not extract request details. Please try again.")
|
66 |
+
else:
|
67 |
+
st.warning("Please enter some text first.")
|
68 |
+
|
69 |
st.title("AI Agent Money Request System")
|
70 |
st.markdown("---")
|
71 |
|
|
|
91 |
# Check if running in cloud environment
|
92 |
is_cloud = voice_handler.is_cloud
|
93 |
|
94 |
+
# Input Method Selection
|
95 |
+
if is_cloud:
|
|
|
|
|
|
|
96 |
st.warning("Voice input is not available in cloud deployment. Using text input only.")
|
97 |
+
render_text_input(language_option)
|
98 |
+
else:
|
99 |
+
tab1, tab2 = st.tabs(["Voice Input", "Text Input"])
|
100 |
+
|
101 |
+
# Voice Input Tab
|
102 |
with tab1:
|
103 |
col1, col2, col3 = st.columns([3, 1, 1])
|
104 |
with col1:
|
|
|
145 |
if 'voice_details' in st.session_state:
|
146 |
del st.session_state['voice_details']
|
147 |
st.success("Memory cleared!")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
148 |
|
149 |
+
# Text Input Tab
|
150 |
+
with tab2:
|
151 |
+
render_text_input(language_option)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
152 |
|
153 |
# Show conversation history
|
154 |
if st.session_state.memory_handler.conversation_history:
|