Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -17,6 +17,9 @@ DATASET_REPO_URL = "https://huggingface.co/datasets/peterpull/MediatorBot"
|
|
| 17 |
DATA_FILENAME = "data.txt"
|
| 18 |
DATA_FILE = os.path.join("data", DATA_FILENAME)
|
| 19 |
|
|
|
|
|
|
|
|
|
|
| 20 |
# I am guessing we need a write access token.
|
| 21 |
HF_TOKEN = os.environ.get("HF_TOKEN")
|
| 22 |
print("HF TOKEN is none?", HF_TOKEN is None)
|
|
@@ -43,15 +46,19 @@ def generate_text() -> str:
|
|
| 43 |
|
| 44 |
def store_message(chatinput: str, chatresponse: str):
|
| 45 |
if chatinput and chatresponse:
|
| 46 |
-
with open(
|
| 47 |
file.write(f"{datetime.now()},{chatinput},{chatresponse}\n")
|
| 48 |
print(f"Wrote to datafile: {datetime.now()},{chatinput},{chatresponse}\n")
|
| 49 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
repo.commit('Update data.txt')
|
| 51 |
print("Committed changes to local repository")
|
| 52 |
repo.push_to_hub()
|
| 53 |
print("Pushed changes to remote repository")
|
| 54 |
-
|
| 55 |
return generate_text()
|
| 56 |
|
| 57 |
|
|
|
|
| 17 |
DATA_FILENAME = "data.txt"
|
| 18 |
DATA_FILE = os.path.join("data", DATA_FILENAME)
|
| 19 |
|
| 20 |
+
NEW_DIR = "new_data"
|
| 21 |
+
NEW_FILE = os.path.join(NEW_DIR, DATA_FILENAME)
|
| 22 |
+
|
| 23 |
# I am guessing we need a write access token.
|
| 24 |
HF_TOKEN = os.environ.get("HF_TOKEN")
|
| 25 |
print("HF TOKEN is none?", HF_TOKEN is None)
|
|
|
|
| 46 |
|
| 47 |
def store_message(chatinput: str, chatresponse: str):
|
| 48 |
if chatinput and chatresponse:
|
| 49 |
+
with open(NEW_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 |
+
os.makedirs(NEW_DIR, exist_ok=True)
|
| 54 |
+
repo.clone(NEW_DIR, exist_ok=True)
|
| 55 |
+
print("Cloned remote repository to new directory")
|
| 56 |
+
shutil.copyfile(DATA_FILE, NEW_FILE)
|
| 57 |
repo.commit('Update data.txt')
|
| 58 |
print("Committed changes to local repository")
|
| 59 |
repo.push_to_hub()
|
| 60 |
print("Pushed changes to remote repository")
|
| 61 |
+
|
| 62 |
return generate_text()
|
| 63 |
|
| 64 |
|