Spaces:
Runtime error
Runtime error
Upload 3 files
Browse files- README.md +5 -5
- app.py +104 -0
- requirements.txt +1 -0
README.md
CHANGED
@@ -1,13 +1,13 @@
|
|
1 |
---
|
2 |
-
title:
|
3 |
-
emoji:
|
4 |
colorFrom: indigo
|
5 |
-
colorTo:
|
6 |
sdk: gradio
|
7 |
-
sdk_version: 3.
|
8 |
app_file: app.py
|
9 |
pinned: false
|
10 |
-
license:
|
11 |
---
|
12 |
|
13 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
1 |
---
|
2 |
+
title: 🧠Generator Calc Writer📖💾 Gradio
|
3 |
+
emoji: Calc📖
|
4 |
colorFrom: indigo
|
5 |
+
colorTo: red
|
6 |
sdk: gradio
|
7 |
+
sdk_version: 3.4.1
|
8 |
app_file: app.py
|
9 |
pinned: false
|
10 |
+
license: apache-2.0
|
11 |
---
|
12 |
|
13 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
app.py
ADDED
@@ -0,0 +1,104 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
|
20 |
+
# Download dataset repo using hub download
|
21 |
+
#try:
|
22 |
+
# hf_hub_download(
|
23 |
+
# repo_id=DATASET_REPO_ID,
|
24 |
+
# filename=DATA_FILENAME,
|
25 |
+
# cache_dir=DATA_DIRNAME,
|
26 |
+
# force_filename=DATA_FILENAME
|
27 |
+
# )
|
28 |
+
#except:
|
29 |
+
# print("file not found")
|
30 |
+
|
31 |
+
#def AIMemory(title: str, story: str):
|
32 |
+
# if title and story:
|
33 |
+
# with open(DATA_FILE, "a") as csvfile:
|
34 |
+
# writer = csv.DictWriter(csvfile, fieldnames=["title", "story", "time"])
|
35 |
+
# writer.writerow({"title": title, "story": story, "time": str(datetime.now())})
|
36 |
+
# uncomment line below to begin saving your changes
|
37 |
+
#commit_url = repo.push_to_hub()
|
38 |
+
# return ""
|
39 |
+
|
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 |
+
#generator1 = gr.Interface.load("bigscience/bloom", api_key=HF_TOKEN)
|
47 |
+
|
48 |
+
|
49 |
+
generator1 = gr.Interface.load("huggingface/gpt2-large", api_key=HF_TOKEN)
|
50 |
+
generator2 = gr.Interface.load("huggingface/EleutherAI/gpt-neo-2.7B", api_key=HF_TOKEN)
|
51 |
+
generator3 = gr.Interface.load("huggingface/EleutherAI/gpt-j-6B", api_key=HF_TOKEN)
|
52 |
+
|
53 |
+
|
54 |
+
def calculator(intro, operator, outro):
|
55 |
+
if operator == "add":
|
56 |
+
output = generator2(intro) + generator3(outro)
|
57 |
+
title = intro + " " + outro
|
58 |
+
# saved = AIMemory(title, output)
|
59 |
+
return output
|
60 |
+
elif operator == "subtract":
|
61 |
+
output = generator2(outro) + generator3(intro)
|
62 |
+
title = outro + " " + intro
|
63 |
+
# saved = AIMemory(title, output)
|
64 |
+
output = output.replace(intro, "").replace(outro, "")
|
65 |
+
return output
|
66 |
+
elif operator == "multiply":
|
67 |
+
output = generator1(intro) + generator2(outro) + generator3(intro)
|
68 |
+
title = intro + " " + outro + " " + intro
|
69 |
+
# saved = AIMemory(title, output)
|
70 |
+
return output
|
71 |
+
elif operator == "divide":
|
72 |
+
output = generator1(outro) + generator2(intro) + generator3(outro)
|
73 |
+
title = outro + " " + intro + " " + outro
|
74 |
+
# saved = AIMemory(title, output)
|
75 |
+
output = output.replace(intro, "").replace(outro, "")
|
76 |
+
return output
|
77 |
+
|
78 |
+
#with open('Mindfulness.txt', 'r') as file:
|
79 |
+
# context = file.read()
|
80 |
+
#contextBox = gr.Textbox(lines=3, default=context, label="Story starter")
|
81 |
+
|
82 |
+
examples = [
|
83 |
+
["Telling my daughter garlic is good for you. Good immune system and keeps pests away. Ticks, mosquitos, vampires... men.", "multiply", "Two guys walk into a bar. The third guy ducks."],
|
84 |
+
["Why was the musician arrested? He got in treble.", "add", "What did the Spanish musician say when he went fishing? Castanets!"],
|
85 |
+
["To save the planet with good looks and comedy,", "add", "I was going to organize a space-themed birthday party for my son... ...but I could not planet."],
|
86 |
+
["In America, people rob banks. In Soviet Russia, Banks rob you!", "multiply", "My roommate just told me he tried to walk to Russia from Alaska. He pulled up short because he could not get his Bering Strait."],
|
87 |
+
["Why does a chicken coop have two doors? Because if had four doors it would be a chicken sedan!", "multiply", "Why did the chicken cross the park? To get to the other slide."],
|
88 |
+
["What type of shoes do ninjas wear? Sneakers", "add", "Can a ninja bring a ninja star into the airport? Shuriken."],
|
89 |
+
["To save the planet with good looks and comedy find your", "multiply", "Everybody laughed at me when I told them I was going to be a comedian. I thought well, thats not bad for a start."]
|
90 |
+
]
|
91 |
+
|
92 |
+
demo = gr.Interface(
|
93 |
+
calculator,
|
94 |
+
[
|
95 |
+
"text",
|
96 |
+
gr.Radio(["add", "subtract", "multiply", "divide"]),
|
97 |
+
"text"
|
98 |
+
],
|
99 |
+
"text",
|
100 |
+
examples=examples,
|
101 |
+
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",
|
102 |
+
live=True,
|
103 |
+
)
|
104 |
+
demo.launch()
|
requirements.txt
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
transformers
|