ZeeAI1 commited on
Commit
db0b008
·
verified ·
1 Parent(s): 691e9e9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -13
app.py CHANGED
@@ -314,35 +314,29 @@ def chat_function(message, history, state=None):
314
  if message.lower().startswith("t-account "):
315
  account_name = message[10:].strip()
316
  if account_name:
317
- return generate_t_account(account_name), state
318
- return "Please specify an account name.", state
319
 
320
  # Parse prompt and generate entry
321
  parsed, state = parse_prompt(message, state)
322
  response, state = generate_journal_entry(parsed, state)
323
 
324
- # Append to history
325
- if history is not None:
326
- history.append((message, response))
327
- else:
328
- history = [(message, response)]
329
-
330
- logging.info(f"Response: {response}")
331
- return response, state
332
 
333
  # Gradio interface
334
  with gr.Blocks() as demo:
335
  gr.Markdown("# AI ERP System")
336
  gr.Markdown("Enter accounting prompts like 'Bought a laptop for $200' or 't-account Laptop'. The system will ask for clarification if needed.")
337
- chatbot = gr.Chatbot()
338
  msg = gr.Textbox(placeholder="Type your prompt here...", lines=2)
339
  clear = gr.Button("Clear")
340
 
341
  # Maintain state
342
  state = gr.State({})
343
 
344
- msg.submit(chat_function, [msg, chatbot, state], [chatbot, state], _js="() => {return false;}")
345
- clear.click(lambda: (None, []), None, [chatbot, state], queue=False)
346
 
347
  # Launch Gradio
348
  if __name__ == "__main__":
 
314
  if message.lower().startswith("t-account "):
315
  account_name = message[10:].strip()
316
  if account_name:
317
+ return {"role": "assistant", "content": generate_t_account(account_name)}, state
318
+ return {"role": "assistant", "content": "Please specify an account name."}, state
319
 
320
  # Parse prompt and generate entry
321
  parsed, state = parse_prompt(message, state)
322
  response, state = generate_journal_entry(parsed, state)
323
 
324
+ # Format response for Gradio
325
+ return {"role": "assistant", "content": response}, state
 
 
 
 
 
 
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=2)
333
  clear = gr.Button("Clear")
334
 
335
  # Maintain state
336
  state = gr.State({})
337
 
338
+ msg.submit(chat_function, [msg, chatbot, state], [chatbot, state])
339
+ clear.click(lambda: ({"role": "assistant", "content": None}, []), None, [chatbot, state], queue=False)
340
 
341
  # Launch Gradio
342
  if __name__ == "__main__":