SamiKoen commited on
Commit
1e21f5d
·
verified ·
1 Parent(s): 0bc1648

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -9
app.py CHANGED
@@ -30,15 +30,37 @@ for item in root.findall('item'):
30
  products.append((name, item_info, full_name))
31
 
32
  # Sohbet geçmişini kalıcı depolamaya yazan fonksiyon
33
- def log_chat(history):
34
- # Hugging Face Spaces persistent storage, genellikle /mnt/data dizininde yer alır
35
- file_path = "/mnt/data/sohbet_kaydi.json"
36
- log_entry = {
37
- "timestamp": datetime.now().isoformat(),
38
- "chat_history": history
39
- }
40
- with open(file_path, "a", encoding="utf-8") as f:
41
- f.write(json.dumps(log_entry, ensure_ascii=False) + "\n")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
42
 
43
  def predict(system_msg, inputs, top_p, temperature, chat_counter, chatbot=[], history=[]):
44
  headers = {
 
30
  products.append((name, item_info, full_name))
31
 
32
  # Sohbet geçmişini kalıcı depolamaya yazan fonksiyon
33
+ DATA_FILENAME = "data.csv"
34
+ DATA_FILE = os.path.join("/data", DATA_FILENAME)
35
+
36
+ def generate_html() -> str:
37
+ with open(DATA_FILE) as csvfile:
38
+ reader = csv.reader(csvfile)
39
+ rows = []
40
+ for row in reader:
41
+ print(row)
42
+ rows.append(row)
43
+ print(rows)
44
+ if len(rows) == 0:
45
+ return "no messages yet"
46
+ else:
47
+ html = "<div class='chatbot'>"
48
+ print(row)
49
+ for row in rows:
50
+ html += "<div>"
51
+ html += f"<span>{row[0]}</span>"
52
+ html += f"<span class='message'>{row[1]}</span>"
53
+ html += "</div>"
54
+ html += "</div>"
55
+ return html
56
+
57
+
58
+ def store_message(name: str, message: str):
59
+ if name and message:
60
+ with open(DATA_FILE, "a") as csvfile:
61
+ csv.writer(csvfile).writerow([name, message])
62
+
63
+ return generate_html()
64
 
65
  def predict(system_msg, inputs, top_p, temperature, chat_counter, chatbot=[], history=[]):
66
  headers = {