File size: 632 Bytes
109d23a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import os
import json
import re

def load_small_talks():
    """Loads small talk responses from a JSON file located in the same directory as app.py."""
    json_path = "small_talks.json"  # Direct relative path

    if not os.path.exists(json_path):
        raise FileNotFoundError(f"File not found: {os.path.abspath(json_path)}")

    with open(json_path, "r", encoding="utf-8") as file:
        return json.load(file)

small_talks = load_small_talks()

def clean_input(user_input):
    """Removes punctuation and converts input to lowercase."""
    return re.sub(r'[^\w\s]', '', user_input).strip().lower()