Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -43,16 +43,23 @@ def generate_text() -> str:
|
|
| 43 |
user, chatbot, time = row_parts
|
| 44 |
text += f"Time: {time}\nUser: {user}\nChatbot: {chatbot}\n\n"
|
| 45 |
return text if text else "No messages yet"
|
| 46 |
-
|
| 47 |
|
| 48 |
def store_message(chatinput: str, chatresponse: str):
|
| 49 |
if chatinput and chatresponse:
|
| 50 |
with open(DATA_FILE, "a") as file:
|
| 51 |
file.write(f"{datetime.now()},{chatinput},{chatresponse}\n")
|
| 52 |
print(f"Wrote to datafile: {datetime.now()},{chatinput},{chatresponse}\n")
|
| 53 |
-
|
| 54 |
-
return generate_text()
|
| 55 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 56 |
|
| 57 |
#gets the index file which is the context data
|
| 58 |
def get_index(index_file_path):
|
|
@@ -66,7 +73,7 @@ def get_index(index_file_path):
|
|
| 66 |
|
| 67 |
index = get_index(INDEX_FILE)
|
| 68 |
|
| 69 |
-
# passes the prompt to the chatbot
|
| 70 |
def chatbot(input_text, mentioned_person='Mediator John Haynes', confidence_threshold=0.5):
|
| 71 |
prompt = f"You are {mentioned_person}. Answer this: {input_text}. Only reply from the contextual data, or say you don't know. At the end of your answer ask an insightful question."
|
| 72 |
response = index.query(prompt, response_mode="default")
|
|
@@ -87,7 +94,4 @@ iface = Interface(
|
|
| 87 |
title="AI Chatbot trained on J. Haynes mediation material, v0.5",
|
| 88 |
description=about)
|
| 89 |
|
| 90 |
-
iface.launch()
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
|
|
|
| 43 |
user, chatbot, time = row_parts
|
| 44 |
text += f"Time: {time}\nUser: {user}\nChatbot: {chatbot}\n\n"
|
| 45 |
return text if text else "No messages yet"
|
|
|
|
| 46 |
|
| 47 |
def store_message(chatinput: str, chatresponse: str):
|
| 48 |
if chatinput and chatresponse:
|
| 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 |
+
# Push back to hub every 10th time the function is called
|
| 54 |
+
if store_message.count_calls % 10 == 0:
|
| 55 |
+
print("Pushing back to Hugging Face model hub")
|
| 56 |
+
# Call the push_to_hub() function to push the changes to the hub
|
| 57 |
+
push_to_hub(commit_message="Added new chat data")
|
| 58 |
+
store_message.count_calls += 1
|
| 59 |
+
|
| 60 |
+
return generate_text()
|
| 61 |
+
|
| 62 |
+
store_message.count_calls = 1 #initiases the count at one. We want to count how many messages stored before pushing back to repo.
|
| 63 |
|
| 64 |
#gets the index file which is the context data
|
| 65 |
def get_index(index_file_path):
|
|
|
|
| 73 |
|
| 74 |
index = get_index(INDEX_FILE)
|
| 75 |
|
| 76 |
+
# passes the prompt to the chatbot
|
| 77 |
def chatbot(input_text, mentioned_person='Mediator John Haynes', confidence_threshold=0.5):
|
| 78 |
prompt = f"You are {mentioned_person}. Answer this: {input_text}. Only reply from the contextual data, or say you don't know. At the end of your answer ask an insightful question."
|
| 79 |
response = index.query(prompt, response_mode="default")
|
|
|
|
| 94 |
title="AI Chatbot trained on J. Haynes mediation material, v0.5",
|
| 95 |
description=about)
|
| 96 |
|
| 97 |
+
iface.launch()
|
|
|
|
|
|
|
|
|