File size: 1,135 Bytes
9f70380
 
 
5ee6b7b
9f70380
 
 
5ee6b7b
 
 
 
9f70380
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
eb66b28
 
 
 
 
9f70380
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# 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()