peterpull commited on
Commit
65a1999
·
1 Parent(s): b08381f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -5
app.py CHANGED
@@ -16,8 +16,7 @@ os.environ["OPENAI_API_KEY"] = os.environ['SECRET_CODE']
16
  DATASET_REPO_URL = "https://huggingface.co/datasets/peterpull/MediatorBot"
17
  DATA_FILENAME = "data.txt"
18
  INDEX_FILENAME = "index2.json"
19
- DATA_FILEP = os.path.join("data", DATA_FILENAME)
20
- INDEX_FILE = os.path.join("data", INDEX_FILENAME)
21
 
22
  # we need a write access token.
23
  HF_TOKEN = os.environ.get("HF_TOKEN")
@@ -30,8 +29,12 @@ repo = Repository(
30
  clone_from=DATASET_REPO_URL,
31
  use_auth_token=HF_TOKEN)
32
 
 
 
 
33
  print(f"Repo local_dir: {repo.local_dir}")
34
  print(f"Repo files: {os.listdir(repo.local_dir)}")
 
35
 
36
  def generate_text() -> str:
37
  with open(DATA_FILE) as file:
@@ -59,7 +62,7 @@ def store_message(chatinput: str, chatresponse: str):
59
 
60
  def get_index(index_file_path):
61
  if os.path.exists(index_file_path):
62
- load_json_file(index_file_path)
63
  index_size = os.path.getsize(index_file_path)
64
  print(f"Size of {index_file_path}: {index_size} bytes") #let me know how big json file is.
65
  return GPTSimpleVectorIndex.load_from_disk(index_file_path)
@@ -67,7 +70,7 @@ def get_index(index_file_path):
67
  print(f"Error: '{index_file_path}' does not exist.")
68
  sys.exit()
69
 
70
- def load_json_file(filepath):
71
  with open(filepath, 'r') as f:
72
  file_contents = f.read()
73
  print ("JSON FILE HEADER:")
@@ -76,7 +79,6 @@ def load_json_file(filepath):
76
  index = get_index(INDEX_FILE)
77
 
78
  # passes the prompt to the chatbot
79
-
80
  def chatbot(input_text, mentioned_person='Mediator John Haynes', confidence_threshold=0.5):
81
  prompt = f"You are {mentioned_person}. Answer this: {input_text}. Reply from the contextual data or say you don't know. To finish, ask an insightful question."
82
  response = index.query(prompt, response_mode="default", verbose=True)
 
16
  DATASET_REPO_URL = "https://huggingface.co/datasets/peterpull/MediatorBot"
17
  DATA_FILENAME = "data.txt"
18
  INDEX_FILENAME = "index2.json"
19
+
 
20
 
21
  # we need a write access token.
22
  HF_TOKEN = os.environ.get("HF_TOKEN")
 
29
  clone_from=DATASET_REPO_URL,
30
  use_auth_token=HF_TOKEN)
31
 
32
+ DATA_FILEP = os.path.join("data", DATA_FILENAME)
33
+ INDEX_FILE = os.path.join("data", INDEX_FILENAME)
34
+
35
  print(f"Repo local_dir: {repo.local_dir}")
36
  print(f"Repo files: {os.listdir(repo.local_dir)}")
37
+ print (f"Index file:{INDEX_FILENAME}")
38
 
39
  def generate_text() -> str:
40
  with open(DATA_FILE) as file:
 
62
 
63
  def get_index(index_file_path):
64
  if os.path.exists(index_file_path):
65
+ print_header_json_file(index_file_path)
66
  index_size = os.path.getsize(index_file_path)
67
  print(f"Size of {index_file_path}: {index_size} bytes") #let me know how big json file is.
68
  return GPTSimpleVectorIndex.load_from_disk(index_file_path)
 
70
  print(f"Error: '{index_file_path}' does not exist.")
71
  sys.exit()
72
 
73
+ def print_header_json_file(filepath):
74
  with open(filepath, 'r') as f:
75
  file_contents = f.read()
76
  print ("JSON FILE HEADER:")
 
79
  index = get_index(INDEX_FILE)
80
 
81
  # passes the prompt to the chatbot
 
82
  def chatbot(input_text, mentioned_person='Mediator John Haynes', confidence_threshold=0.5):
83
  prompt = f"You are {mentioned_person}. Answer this: {input_text}. Reply from the contextual data or say you don't know. To finish, ask an insightful question."
84
  response = index.query(prompt, response_mode="default", verbose=True)