Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -13,7 +13,7 @@ os.environ["OPENAI_API_KEY"] = os.environ['SECRET_CODE']
|
|
| 13 |
|
| 14 |
# Need to write to persistent dataset because cannot store temp data on spaces
|
| 15 |
DATASET_REPO_URL = "https://huggingface.co/datasets/peterpull/MediatorBot"
|
| 16 |
-
DATA_FILENAME = "data.
|
| 17 |
DATA_FILE = os.path.join("data", DATA_FILENAME)
|
| 18 |
|
| 19 |
# I am guessing we need a write access token.
|
|
@@ -28,36 +28,33 @@ repo = Repository(
|
|
| 28 |
|
| 29 |
|
| 30 |
def generate_html() -> str:
|
| 31 |
-
with open(DATA_FILE) as
|
| 32 |
-
|
| 33 |
-
rows = []
|
| 34 |
-
for row in reader:
|
| 35 |
-
rows.append(row)
|
| 36 |
rows.reverse()
|
| 37 |
if len(rows) == 0:
|
| 38 |
return "no messages yet"
|
| 39 |
else:
|
| 40 |
html = "<div class='chatbot'>"
|
| 41 |
for row in rows:
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
html += "<div>"
|
| 43 |
-
html += f"<span>{
|
| 44 |
-
html += f"<span class='message'>{
|
| 45 |
-
html += f"<span class='time'>{
|
| 46 |
html += "</div>"
|
| 47 |
html += "</div>"
|
| 48 |
return html
|
| 49 |
|
| 50 |
def store_message(chatinput: str, chatresponse: str):
|
| 51 |
if chatinput and chatresponse:
|
| 52 |
-
with open(DATA_FILE, "a") as
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
writer.writerow(
|
| 56 |
-
{"User": chatinput, "Chatbot": chatresponse, "time": str(datetime.now())}
|
| 57 |
-
)
|
| 58 |
commit_url = repo.push_to_hub()
|
| 59 |
print(commit_url)
|
| 60 |
-
|
| 61 |
return generate_html()
|
| 62 |
|
| 63 |
|
|
|
|
| 13 |
|
| 14 |
# Need to write to persistent dataset because cannot store temp data on spaces
|
| 15 |
DATASET_REPO_URL = "https://huggingface.co/datasets/peterpull/MediatorBot"
|
| 16 |
+
DATA_FILENAME = "data.txt"
|
| 17 |
DATA_FILE = os.path.join("data", DATA_FILENAME)
|
| 18 |
|
| 19 |
# I am guessing we need a write access token.
|
|
|
|
| 28 |
|
| 29 |
|
| 30 |
def generate_html() -> str:
|
| 31 |
+
with open(DATA_FILE) as file:
|
| 32 |
+
rows = file.readlines()
|
|
|
|
|
|
|
|
|
|
| 33 |
rows.reverse()
|
| 34 |
if len(rows) == 0:
|
| 35 |
return "no messages yet"
|
| 36 |
else:
|
| 37 |
html = "<div class='chatbot'>"
|
| 38 |
for row in rows:
|
| 39 |
+
row_parts = row.split(",")
|
| 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"User: {chatinput}, Chatbot: {chatresponse}, Time: {str(datetime.now())}\n")
|
| 55 |
+
# commit changes to repo
|
|
|
|
|
|
|
|
|
|
| 56 |
commit_url = repo.push_to_hub()
|
| 57 |
print(commit_url)
|
|
|
|
| 58 |
return generate_html()
|
| 59 |
|
| 60 |
|