|
|
|
|
|
import gradio as gr |
|
from main import query_index, ask_llm_with_context, initialize_index |
|
|
|
import datetime |
|
|
|
|
|
initialize_index(update_mode="none") |
|
|
|
|
|
def log_question_response(question, answer): |
|
timestamp = datetime.datetime.now().isoformat() |
|
with open("chat_log.txt", "a", encoding="utf-8") as f: |
|
f.write(f"[{timestamp}]\nQ: {question}\nA: {answer}\n\n") |
|
|
|
def legal_assistant(question): |
|
if not question.strip(): |
|
return "Please enter a valid question." |
|
context = query_index(question) |
|
answer = ask_llm_with_context(question, context) |
|
log_question_response(question, answer) |
|
|
|
return answer |
|
|
|
iface = gr.Interface( |
|
fn=legal_assistant, |
|
inputs=gr.Textbox(lines=4, placeholder="Ask about BC land survey law..."), |
|
outputs=gr.Textbox( |
|
lines=30, |
|
max_lines=50, |
|
label="Answer" |
|
), |
|
title="π BC Land Survey Legal Assistant", |
|
description="Ask any question related to BC Land Surveying based on laws, regulations, acts, bulletins, and more.", |
|
) |
|
|
|
iface.launch() |
|
|