Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -49,15 +49,18 @@ def store_message(chatinput: str, chatresponse: str):
|
|
| 49 |
with open(DATA_FILE, "a") as file:
|
| 50 |
file.write(f"{datetime.now()},{chatinput},{chatresponse}\n")
|
| 51 |
print(f"Wrote to datafile: {datetime.now()},{chatinput},{chatresponse}\n")
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
|
|
|
| 55 |
return generate_text()
|
| 56 |
|
| 57 |
|
| 58 |
#gets the index file which is the context data
|
| 59 |
def get_index(index_file_path):
|
| 60 |
if os.path.exists(index_file_path):
|
|
|
|
|
|
|
| 61 |
return GPTSimpleVectorIndex.load_from_disk(index_file_path)
|
| 62 |
else:
|
| 63 |
print(f"Error: '{index_file_path}' does not exist.")
|
|
@@ -66,7 +69,7 @@ def get_index(index_file_path):
|
|
| 66 |
# passes the prompt to the chatbot
|
| 67 |
def chatbot(input_text, mentioned_person='Mediator John Haynes'):
|
| 68 |
index = get_index(INDEX_FILE)
|
| 69 |
-
prompt = f"You are {mentioned_person}: {input_text}\n\n At the end of your answer
|
| 70 |
response = index.query(prompt, response_mode="compact")
|
| 71 |
|
| 72 |
store_message(input_text,response)
|
|
|
|
| 49 |
with open(DATA_FILE, "a") as file:
|
| 50 |
file.write(f"{datetime.now()},{chatinput},{chatresponse}\n")
|
| 51 |
print(f"Wrote to datafile: {datetime.now()},{chatinput},{chatresponse}\n")
|
| 52 |
+
|
| 53 |
+
repo.push_to_hub(files=[str(os.path.join("data", DATA_FILENAME))])
|
| 54 |
+
print("pushed data.txt to repo")
|
| 55 |
+
|
| 56 |
return generate_text()
|
| 57 |
|
| 58 |
|
| 59 |
#gets the index file which is the context data
|
| 60 |
def get_index(index_file_path):
|
| 61 |
if os.path.exists(index_file_path):
|
| 62 |
+
index_size = os.path.getsize(index_file_path)
|
| 63 |
+
print(f"Size of {index_file_path}: {index_size} bytes") #let me know how big json file is.
|
| 64 |
return GPTSimpleVectorIndex.load_from_disk(index_file_path)
|
| 65 |
else:
|
| 66 |
print(f"Error: '{index_file_path}' does not exist.")
|
|
|
|
| 69 |
# passes the prompt to the chatbot
|
| 70 |
def chatbot(input_text, mentioned_person='Mediator John Haynes'):
|
| 71 |
index = get_index(INDEX_FILE)
|
| 72 |
+
prompt = f"You are {mentioned_person}: {input_text}\n\n At the end of your answer ask a provocative question."
|
| 73 |
response = index.query(prompt, response_mode="compact")
|
| 74 |
|
| 75 |
store_message(input_text,response)
|