Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,5 +1,48 @@
|
|
1 |
import gradio as gr
|
2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
def calculator(text1, operation, text2):
|
4 |
if operation == "add":
|
5 |
return text1 + text2
|
|
|
1 |
import gradio as gr
|
2 |
|
3 |
+
|
4 |
+
# PersistDataset -----
|
5 |
+
import os
|
6 |
+
import csv
|
7 |
+
import gradio as gr
|
8 |
+
from gradio import inputs, outputs
|
9 |
+
import huggingface_hub
|
10 |
+
from huggingface_hub import Repository, hf_hub_download, upload_file
|
11 |
+
from datetime import datetime
|
12 |
+
|
13 |
+
# created new dataset as awacke1/MindfulStory.csv
|
14 |
+
DATASET_REPO_URL = "https://huggingface.co/datasets/awacke1/MindfulStory.csv"
|
15 |
+
DATASET_REPO_ID = "awacke1/MindfulStory.csv"
|
16 |
+
DATA_FILENAME = "MindfulStory.csv"
|
17 |
+
DATA_FILE = os.path.join("data", DATA_FILENAME)
|
18 |
+
HF_TOKEN = os.environ.get("HF_TOKEN")
|
19 |
+
# Download dataset repo using hub download
|
20 |
+
try:
|
21 |
+
hf_hub_download(
|
22 |
+
repo_id=DATASET_REPO_ID,
|
23 |
+
filename=DATA_FILENAME,
|
24 |
+
cache_dir=DATA_DIRNAME,
|
25 |
+
force_filename=DATA_FILENAME
|
26 |
+
)
|
27 |
+
except:
|
28 |
+
print("file not found")
|
29 |
+
|
30 |
+
def AIMemory(name: str, message: str):
|
31 |
+
if name and message:
|
32 |
+
with open(DATA_FILE, "a") as csvfile:
|
33 |
+
writer = csv.DictWriter(csvfile, fieldnames=["name", "message", "time"])
|
34 |
+
writer.writerow({"name": name, "message": message, "time": str(datetime.now())})
|
35 |
+
commit_url = repo.push_to_hub()
|
36 |
+
return {"name": name, "message": message, "time": str(datetime.now())}
|
37 |
+
|
38 |
+
with open('Mindfulness.txt', 'r') as file:
|
39 |
+
context = file.read()
|
40 |
+
|
41 |
+
# Set up cloned dataset from repo for operations
|
42 |
+
repo = Repository(
|
43 |
+
local_dir="data", clone_from=DATASET_REPO_URL, use_auth_token=HF_TOKEN
|
44 |
+
)
|
45 |
+
|
46 |
def calculator(text1, operation, text2):
|
47 |
if operation == "add":
|
48 |
return text1 + text2
|