awacke1 commited on
Commit
204ee44
·
1 Parent(s): 4051e9c

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +103 -0
  2. requirements.txt +1 -0
app.py ADDED
@@ -0,0 +1,103 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import os
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(title: str, story: str):
31
+ if title and story:
32
+ with open(DATA_FILE, "a") as csvfile:
33
+ writer = csv.DictWriter(csvfile, fieldnames=["title", "story", "time"])
34
+ writer.writerow({"title": title, "story": story, "time": str(datetime.now())})
35
+ commit_url = repo.push_to_hub()
36
+ return ""
37
+
38
+
39
+ # Set up cloned dataset from repo for operations
40
+ repo = Repository(
41
+ local_dir="data", clone_from=DATASET_REPO_URL, use_auth_token=HF_TOKEN
42
+ )
43
+
44
+ generator1 = gr.Interface.load("huggingface/gpt2-large", api_key=HF_TOKEN)
45
+ generator2 = gr.Interface.load("huggingface/EleutherAI/gpt-neo-2.7B", api_key=HF_TOKEN)
46
+ generator3 = gr.Interface.load("huggingface/EleutherAI/gpt-j-6B", api_key=HF_TOKEN)
47
+
48
+ def calculator(intro, operator, outro):
49
+ if operator == "add":
50
+ output = generator2(intro) + generator3(outro)
51
+ title = intro + " " + outro
52
+ saved = AIMemory(title, output)
53
+ return output
54
+ elif operator == "subtract":
55
+ output = generator2(outro) + generator3(intro)
56
+ title = outro + " " + intro
57
+ saved = AIMemory(title, output)
58
+ output = output.replace(intro, "").replace(outro, "")
59
+ return output
60
+ elif operator == "multiply":
61
+ output = generator1(intro) + generator2(outro) + generator3(intro)
62
+ title = intro + " " + outro + " " + intro
63
+ saved = AIMemory(title, output)
64
+ return output
65
+ elif operator == "divide":
66
+ output = generator1(outro) + generator2(intro) + generator3(outro)
67
+ title = outro + " " + intro + " " + outro
68
+ saved = AIMemory(title, output)
69
+ output = output.replace(intro, "").replace(outro, "")
70
+ return output
71
+
72
+ #with open('Mindfulness.txt', 'r') as file:
73
+ # context = file.read()
74
+ #contextBox = gr.Textbox(lines=3, default=context, label="Story starter")
75
+
76
+ examples = [
77
+ ["Music and art make me feel", "add", "Path to Health and Happiness"],
78
+ ["Feel better each day when you awake by", "add", "Mental Body Scan"],
79
+ ["Feel better physically by", "add", "Stretch, Calm, Breath"],
80
+ ["Practicing mindfulness each day", "add", "Walk Feel"],
81
+ ["Be happier by", "add", "Brain gamification"],
82
+ ["Meditation can improve health", "add", "Deep Breaths"],
83
+ ["Spending time outdoors", "add", "Find Joy"],
84
+ ["Stress is relieved by quieting your mind, getting exercise and time with nature", "add", "Relieve Pain"],
85
+ ["Break the cycle of stress and anxiety", "add", "Yoga and Meditation"],
86
+ ["Feel calm in stressful situations", "add", "Neocortex Tools and Techniques"],
87
+ ["Deal with work pressure", "add", "Strengthen Attention"],
88
+ ["Learn to reduce feelings of overwhelmed", "add", "Easy Daily Activities"]
89
+ ]
90
+
91
+ demo = gr.Interface(
92
+ calculator,
93
+ [
94
+ "text",
95
+ gr.Radio(["add", "subtract", "multiply", "divide"]),
96
+ "text"
97
+ ],
98
+ "text",
99
+ examples=examples,
100
+ article="Saved story memory dataset: https://huggingface.co/datasets/awacke1/MindfulStory.csv with available models to use from text gen: https://huggingface.co/models?pipeline_tag=text-generation&sort=downloads",
101
+ live=True,
102
+ )
103
+ demo.launch()
requirements.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ transformers