Update app.py
Browse files
app.py
CHANGED
@@ -306,11 +306,12 @@ def chat_function(message, history, state=None):
|
|
306 |
if message.lower().startswith("t-account "):
|
307 |
account_name = message[10:].strip()
|
308 |
if account_name:
|
309 |
-
|
310 |
-
|
311 |
-
|
312 |
-
|
313 |
-
|
|
|
314 |
|
315 |
if history is not None:
|
316 |
history.append({"role": "user", "content": message})
|
@@ -321,20 +322,20 @@ def chat_function(message, history, state=None):
|
|
321 |
{"role": "assistant", "content": response}
|
322 |
]
|
323 |
|
324 |
-
return history, state
|
325 |
|
326 |
# Gradio interface
|
327 |
with gr.Blocks() as demo:
|
328 |
gr.Markdown("# AI ERP System")
|
329 |
gr.Markdown("Enter accounting prompts like 'Bought a laptop for $200' or 't-account Laptop'. The system will ask for clarification if needed.")
|
330 |
chatbot = gr.Chatbot(type="messages")
|
331 |
-
msg = gr.Textbox(placeholder="Type your prompt here...", lines=
|
332 |
clear = gr.Button("Clear")
|
333 |
|
334 |
state = gr.State({})
|
335 |
|
336 |
-
msg.submit(chat_function, [msg, chatbot, state], [chatbot, state])
|
337 |
-
clear.click(lambda: ([], {}), None, [chatbot, state], queue=False)
|
338 |
|
339 |
# Launch Gradio
|
340 |
if __name__ == "__main__":
|
|
|
306 |
if message.lower().startswith("t-account "):
|
307 |
account_name = message[10:].strip()
|
308 |
if account_name:
|
309 |
+
response = generate_t_account(account_name)
|
310 |
+
else:
|
311 |
+
response = "Please specify an account name."
|
312 |
+
else:
|
313 |
+
parsed, state = parse_prompt(message, state)
|
314 |
+
response, state = generate_journal_entry(parsed, state)
|
315 |
|
316 |
if history is not None:
|
317 |
history.append({"role": "user", "content": message})
|
|
|
322 |
{"role": "assistant", "content": response}
|
323 |
]
|
324 |
|
325 |
+
return history, state, "" # Clear the textbox by returning an empty string
|
326 |
|
327 |
# Gradio interface
|
328 |
with gr.Blocks() as demo:
|
329 |
gr.Markdown("# AI ERP System")
|
330 |
gr.Markdown("Enter accounting prompts like 'Bought a laptop for $200' or 't-account Laptop'. The system will ask for clarification if needed.")
|
331 |
chatbot = gr.Chatbot(type="messages")
|
332 |
+
msg = gr.Textbox(placeholder="Type your prompt here...", lines=1, submit_btn=None)
|
333 |
clear = gr.Button("Clear")
|
334 |
|
335 |
state = gr.State({})
|
336 |
|
337 |
+
msg.submit(chat_function, [msg, chatbot, state], [chatbot, state, msg])
|
338 |
+
clear.click(lambda: ([], {}, ""), None, [chatbot, state, msg], queue=False)
|
339 |
|
340 |
# Launch Gradio
|
341 |
if __name__ == "__main__":
|