|
|
| import os |
| import gradio as gr |
| import sqlite3 |
| from dotenv import load_dotenv |
| import openai |
| from utils import generate_double_entry, save_transaction |
|
|
| load_dotenv() |
|
|
| openai.api_key = os.getenv(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) |
| openai.api_base = "https://api.groq.com/openai/v1" |
|
|
| def call_groq(prompt): |
| response = openai.ChatCompletion.create( |
| model="mixtral-8x7b-instruct", |
| messages=[{"role": "user", "content": prompt}] |
| ) |
| return response['choices'][0]['message']['content'] |
|
|
| def accounting_chatbot(user_input): |
| llm_output = call_groq(user_input) |
| debit, credit, amount = generate_double_entry(llm_output) |
| save_transaction(debit, credit, amount, user_input) |
|
|
| output = f"**Double Entry**\n- Debit: {debit}\n- Credit: {credit}\n- Amount: {amount}\n\n🧠 {llm_output}" |
| return output |
|
|
| demo = gr.ChatInterface(fn=accounting_chatbot, title="AI Accounting Assistant") |
| demo.launch() |
|
|