Update app.py
Browse files
app.py
CHANGED
@@ -44,31 +44,31 @@ def store_message(name: str, message: str, outputfileName: str):
|
|
44 |
basedir = os.path.dirname(__file__)
|
45 |
savePath = outputfileName
|
46 |
|
47 |
-
# if file
|
48 |
from os.path import exists
|
49 |
file_exists = exists(savePath)
|
50 |
|
51 |
-
if
|
52 |
-
with open(savePath, "w") as f:
|
53 |
-
f.write(
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
df = df.sort_values(df.columns[0],ascending=False)
|
70 |
return df
|
71 |
|
|
|
72 |
mname = "facebook/blenderbot-400M-distill"
|
73 |
model = BlenderbotForConditionalGeneration.from_pretrained(mname)
|
74 |
tokenizer = BlenderbotTokenizer.from_pretrained(mname)
|
|
|
44 |
basedir = os.path.dirname(__file__)
|
45 |
savePath = outputfileName
|
46 |
|
47 |
+
# if file doesn't exist, create it with labels and a few default rows
|
48 |
from os.path import exists
|
49 |
file_exists = exists(savePath)
|
50 |
|
51 |
+
if not file_exists:
|
52 |
+
with open(savePath, "w") as f: # Create and write column headers and default content
|
53 |
+
f.write("time, message, name\n") # Column headers
|
54 |
+
# Write a few default rows (if needed)
|
55 |
+
f.write(f"{str(datetime.now())}, Welcome to Chatback!, System\n")
|
56 |
+
f.write(f"{str(datetime.now())}, How can I assist you today?, System\n")
|
57 |
+
|
58 |
+
# Proceed to add the actual message if name and message are provided
|
59 |
+
if name and message:
|
60 |
+
with open(savePath, "a") as csvfile:
|
61 |
+
writer = csv.DictWriter(csvfile, fieldnames=["time", "message", "name"])
|
62 |
+
writer.writerow(
|
63 |
+
{"time": str(datetime.now()), "message": message.strip(), "name": name.strip()}
|
64 |
+
)
|
65 |
+
|
66 |
+
# Load and sort the dataframe
|
67 |
+
df = pd.read_csv(savePath)
|
68 |
+
df = df.sort_values(df.columns[0], ascending=False)
|
|
|
69 |
return df
|
70 |
|
71 |
+
|
72 |
mname = "facebook/blenderbot-400M-distill"
|
73 |
model = BlenderbotForConditionalGeneration.from_pretrained(mname)
|
74 |
tokenizer = BlenderbotTokenizer.from_pretrained(mname)
|