sujitb commited on
Commit
d944fdb
1 Parent(s): 976a040

Added logging

Browse files
Files changed (1) hide show
  1. app.py +26 -3
app.py CHANGED
@@ -9,7 +9,10 @@ import pandas as pd
9
  import os
10
 
11
  from huggingface_hub import HfFileSystem
12
- fs = HfFileSystem()
 
 
 
13
 
14
  import time
15
 
@@ -79,6 +82,24 @@ def response_generator(response):
79
  yield word + " "
80
  time.sleep(0.05)
81
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
82
  st.title('CLLM Answering Machine')
83
 
84
  # Initialize chat history
@@ -162,8 +183,9 @@ if QUESTION:
162
 
163
  now= str(datetime.utcnow())
164
  df_log.loc[len(df_log)]=[QUESTION,url,score,ans,now]
 
165
  #df.to_csv("hf://datasets/sujitb/data/test.csv")
166
- df_log.to_csv("hf://datasets/sujitb/data/"+logfile)
167
 
168
  else:
169
  #st.write("No matches for query")
@@ -174,4 +196,5 @@ if QUESTION:
174
 
175
  now= str(datetime.utcnow())
176
  df_log.loc[len(df_log)]=[QUESTION,'No match',0,'-',now]
177
- df_log.to_csv("hf://datasets/sujitb/data/"+logfile)
 
 
9
  import os
10
 
11
  from huggingface_hub import HfFileSystem
12
+
13
+ token = os.getenv('git')
14
+
15
+ fs = HfFileSystem(token=token)
16
 
17
  import time
18
 
 
82
  yield word + " "
83
  time.sleep(0.05)
84
 
85
+ def write_log(query,url, score, ans, ts):
86
+ # Construct new row
87
+ score = str(score)
88
+ ans = ans.replace('"', '""')
89
+ new_row = f'\n"{query}","{url}",{score},"{ans}","{ts}"'
90
+
91
+ with fs.open("datasets/sujitb/data/querylog.csv", "r") as f:
92
+ buffer = f.read()
93
+
94
+ # Append the new row to buffer
95
+ buffer += new_row
96
+
97
+ # Write the buffer to the file in "W" mode
98
+ with fs.open("datasets/sujitb/data/querylog.csv", "w",encoding="utf-8") as f:
99
+ f.write(buffer)
100
+
101
+ return
102
+
103
  st.title('CLLM Answering Machine')
104
 
105
  # Initialize chat history
 
183
 
184
  now= str(datetime.utcnow())
185
  df_log.loc[len(df_log)]=[QUESTION,url,score,ans,now]
186
+ write_log(QUESTION,url, score, ans, now)
187
  #df.to_csv("hf://datasets/sujitb/data/test.csv")
188
+ #df_log.to_csv("hf://datasets/sujitb/data/"+logfile)
189
 
190
  else:
191
  #st.write("No matches for query")
 
196
 
197
  now= str(datetime.utcnow())
198
  df_log.loc[len(df_log)]=[QUESTION,'No match',0,'-',now]
199
+ #df_log.to_csv("hf://datasets/sujitb/data/"+logfile)
200
+ write_log(QUESTION,url, score, ans, now)