Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -27,36 +27,23 @@ repo = Repository(
|
|
| 27 |
use_auth_token=HF_TOKEN)
|
| 28 |
|
| 29 |
|
| 30 |
-
def
|
| 31 |
with open(DATA_FILE) as file:
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
user = row_parts[0].strip()
|
| 41 |
-
chatbot = row_parts[1].strip()
|
| 42 |
-
time = row_parts[2].strip()
|
| 43 |
-
html += "<div>"
|
| 44 |
-
html += f"<span>{user}</span>"
|
| 45 |
-
html += f"<span class='message'>{chatbot}</span>"
|
| 46 |
-
html += f"<span class='time'>{time}</span>"
|
| 47 |
-
html += "</div>"
|
| 48 |
-
html += "</div>"
|
| 49 |
-
return html
|
| 50 |
|
| 51 |
def store_message(chatinput: str, chatresponse: str):
|
| 52 |
if chatinput and chatresponse:
|
| 53 |
with open(DATA_FILE, "a") as file:
|
| 54 |
-
file.write(f"
|
| 55 |
-
# commit changes to repo
|
| 56 |
-
commit_url = repo.push_to_hub()
|
| 57 |
-
print(commit_url)
|
| 58 |
-
return generate_html()
|
| 59 |
|
|
|
|
| 60 |
|
| 61 |
#gets the index file which is the context data
|
| 62 |
def get_index(index_file_path):
|
|
|
|
| 27 |
use_auth_token=HF_TOKEN)
|
| 28 |
|
| 29 |
|
| 30 |
+
def generate_text() -> str:
|
| 31 |
with open(DATA_FILE) as file:
|
| 32 |
+
text = ""
|
| 33 |
+
for line in file:
|
| 34 |
+
row_parts = line.strip().split(",")
|
| 35 |
+
if len(row_parts) != 3:
|
| 36 |
+
continue
|
| 37 |
+
user, chatbot, time = row_parts
|
| 38 |
+
text += f"User: {user}\nChatbot: {chatbot}\nTime: {time}\n\n"
|
| 39 |
+
return text if text else "No messages yet"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
|
| 41 |
def store_message(chatinput: str, chatresponse: str):
|
| 42 |
if chatinput and chatresponse:
|
| 43 |
with open(DATA_FILE, "a") as file:
|
| 44 |
+
file.write(f"{chatinput},{chatresponse},{datetime.now()}\n")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
|
| 46 |
+
return generate_text()
|
| 47 |
|
| 48 |
#gets the index file which is the context data
|
| 49 |
def get_index(index_file_path):
|