muryshev commited on
Commit
3f29565
1 Parent(s): df89b42

Update app.py

Browse files

Added xml logging

Files changed (1) hide show
  1. app.py +13 -7
app.py CHANGED
@@ -6,8 +6,8 @@ from huggingface_hub import snapshot_download, Repository
6
  import huggingface_hub
7
  import gc
8
  import os.path
9
- import csv
10
  from datetime import datetime
 
11
 
12
  SYSTEM_PROMPT = "Ты — русскоязычный автоматический ассистент. Ты максимально точно и отвечаешь на запросы пользователя, используя русский язык."
13
  SYSTEM_TOKEN = 1788
@@ -55,7 +55,7 @@ model_path = snapshot_download(repo_id=repo_name, allow_patterns=model_name) + '
55
  app.logger.info('Model path: ' + model_path)
56
 
57
  DATASET_REPO_URL = "https://huggingface.co/datasets/muryshev/saiga-chat"
58
- DATA_FILENAME = "data-internal.csv"
59
  DATA_FILE = os.path.join("dataset", DATA_FILENAME)
60
 
61
  HF_TOKEN = os.environ.get("HF_TOKEN")
@@ -69,11 +69,17 @@ repo = Repository(
69
 
70
  def log(req: str = '', resp: str = ''):
71
  if req or resp:
72
- with open(DATA_FILE, "a") as csvfile:
73
- writer = csv.DictWriter(csvfile, fieldnames=["request", "response", "time"])
74
- writer.writerow(
75
- {"request": req, "response": resp, "time": str(datetime.now())}
76
- )
 
 
 
 
 
 
77
  commit_url = repo.push_to_hub()
78
  app.logger.info(commit_url)
79
 
 
6
  import huggingface_hub
7
  import gc
8
  import os.path
 
9
  from datetime import datetime
10
+ import xml.etree.ElementTree as ET
11
 
12
  SYSTEM_PROMPT = "Ты — русскоязычный автоматический ассистент. Ты максимально точно и отвечаешь на запросы пользователя, используя русский язык."
13
  SYSTEM_TOKEN = 1788
 
55
  app.logger.info('Model path: ' + model_path)
56
 
57
  DATASET_REPO_URL = "https://huggingface.co/datasets/muryshev/saiga-chat"
58
+ DATA_FILENAME = "data-saiga-cuda-chat.xml"
59
  DATA_FILE = os.path.join("dataset", DATA_FILENAME)
60
 
61
  HF_TOKEN = os.environ.get("HF_TOKEN")
 
69
 
70
  def log(req: str = '', resp: str = ''):
71
  if req or resp:
72
+ element = ET.Element("row", {"time": str(datetime.now()) })
73
+ req_element = ET.SubElement(element, "request")
74
+ req_element.text = req
75
+ resp_element = ET.SubElement(element, "response")
76
+ resp_element.text = resp
77
+
78
+ element.text = "\n".join(article["content"])
79
+
80
+ with open(destination_path, "ab+") as xml_file:
81
+ xml_file.write(ET.tostring(element, encoding="utf-8"))
82
+
83
  commit_url = repo.push_to_hub()
84
  app.logger.info(commit_url)
85