legal_rag / app.py
allenlsl's picture
Update app.py
5ee6b7b verified
raw
history blame contribute delete
1.14 kB
# interface.py
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, # Show 15 lines by default
max_lines=50, # Allow scroll for longer answers
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()