Sudhansu commited on
Commit
2e5c8d0
1 Parent(s): 9bb3562

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +99 -0
  2. requirements.txt +1 -0
app.py ADDED
@@ -0,0 +1,99 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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("bigscience/bloom", api_key=HF_TOKEN)
45
+
46
+
47
+ generator1 = gr.Interface.load("huggingface/gpt2-large", api_key=HF_TOKEN)
48
+ generator2 = gr.Interface.load("huggingface/EleutherAI/gpt-neo-2.7B", api_key=HF_TOKEN)
49
+ generator3 = gr.Interface.load("huggingface/EleutherAI/gpt-j-6B", api_key=HF_TOKEN)
50
+
51
+
52
+ def calculator(intro, operator, outro):
53
+ if operator == "add":
54
+ output = generator2(intro) + generator3(outro)
55
+ title = intro + " " + outro
56
+ saved = AIMemory(title, output)
57
+ return output
58
+ elif operator == "subtract":
59
+ output = generator2(outro) + generator3(intro)
60
+ title = outro + " " + intro
61
+ saved = AIMemory(title, output)
62
+ output = output.replace(intro, "").replace(outro, "")
63
+ return output
64
+ elif operator == "multiply":
65
+ output = generator1(intro) + generator2(outro) + generator3(intro)
66
+ title = intro + " " + outro + " " + intro
67
+ saved = AIMemory(title, output)
68
+ return output
69
+ elif operator == "divide":
70
+ output = generator1(outro) + generator2(intro) + generator3(outro)
71
+ title = outro + " " + intro + " " + outro
72
+ saved = AIMemory(title, output)
73
+ output = output.replace(intro, "").replace(outro, "")
74
+ return output
75
+
76
+ #with open('Mindfulness.txt', 'r') as file:
77
+ # context = file.read()
78
+ #contextBox = gr.Textbox(lines=3, default=context, label="Story starter")
79
+ #Two space marines named Liev Schreiber and Will Sasso take up arms to save the planet from an alien invasion. These two dashing strong men play a comedic role in the science fiction movie of the future where even barnaby bunny is willing to join their wacky gang of space marines to save the planet with good looks and comedy.
80
+
81
+ examples = [
82
+ ["Two space marines take up arms to save the planet from an alien invasion.", "multiply", "These two dashing strong actors play a comedic role in the science fiction movie of the future"],
83
+ ["These two dashing strong actors play a comedic role in the science fiction movie of the future", "add", "Barnaby bunny is willing to join their wacky gang of space marines"],
84
+ ["to save the planet with good looks and comedy", "add", "Two space marines become best friends as they assist with saving the world from the alien invasion"]
85
+ ]
86
+
87
+ demo = gr.Interface(
88
+ calculator,
89
+ [
90
+ "text",
91
+ gr.Radio(["add", "subtract", "multiply", "divide"]),
92
+ "text"
93
+ ],
94
+ "text",
95
+ examples=examples,
96
+ 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",
97
+ live=True,
98
+ )
99
+ demo.launch()
requirements.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ transformers