Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,4 +1,5 @@
|
|
1 |
import gradio as gr
|
|
|
2 |
from transformers import pipeline
|
3 |
title = "Transformers 📗 Sentence to Paragraph ❤️ For Mindfulness"
|
4 |
examples = [
|
@@ -19,8 +20,95 @@ from gradio import inputs
|
|
19 |
from gradio.inputs import Textbox
|
20 |
from gradio import outputs
|
21 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
generator2 = gr.Interface.load("huggingface/EleutherAI/gpt-neo-2.7B")
|
23 |
generator3 = gr.Interface.load("huggingface/EleutherAI/gpt-j-6B")
|
24 |
generator1 = gr.Interface.load("huggingface/gpt2-large")
|
25 |
-
gr.Parallel(generator1,
|
26 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
+
import os
|
3 |
from transformers import pipeline
|
4 |
title = "Transformers 📗 Sentence to Paragraph ❤️ For Mindfulness"
|
5 |
examples = [
|
|
|
20 |
from gradio.inputs import Textbox
|
21 |
from gradio import outputs
|
22 |
|
23 |
+
# PersistDataset -----
|
24 |
+
import os
|
25 |
+
import csv
|
26 |
+
import gradio as gr
|
27 |
+
from gradio import inputs, outputs
|
28 |
+
import huggingface_hub
|
29 |
+
from huggingface_hub import Repository, hf_hub_download, upload_file
|
30 |
+
from datetime import datetime
|
31 |
+
DATASET_REPO_URL = "https://huggingface.co/datasets/awacke1/Carddata.csv"
|
32 |
+
DATASET_REPO_ID = "awacke1/Carddata.csv"
|
33 |
+
DATA_FILENAME = "Carddata.csv"
|
34 |
+
DATA_FILE = os.path.join("data", DATA_FILENAME)
|
35 |
+
HF_TOKEN = os.environ.get("HF_TOKEN")
|
36 |
+
|
37 |
+
SCRIPT = """
|
38 |
+
<script>
|
39 |
+
if (!window.hasBeenRun) {
|
40 |
+
window.hasBeenRun = true;
|
41 |
+
console.log("should only happen once");
|
42 |
+
document.querySelector("button.submit").click();
|
43 |
+
}
|
44 |
+
</script>
|
45 |
+
"""
|
46 |
+
|
47 |
+
try:
|
48 |
+
hf_hub_download(
|
49 |
+
repo_id=DATASET_REPO_ID,
|
50 |
+
filename=DATA_FILENAME,
|
51 |
+
cache_dir=DATA_DIRNAME,
|
52 |
+
force_filename=DATA_FILENAME
|
53 |
+
)
|
54 |
+
except:
|
55 |
+
print("file not found")
|
56 |
+
repo = Repository(
|
57 |
+
local_dir="data", clone_from=DATASET_REPO_URL, use_auth_token=HF_TOKEN
|
58 |
+
)
|
59 |
+
|
60 |
+
def generate_html() -> str:
|
61 |
+
with open(DATA_FILE) as csvfile:
|
62 |
+
reader = csv.DictReader(csvfile)
|
63 |
+
rows = []
|
64 |
+
for row in reader:
|
65 |
+
rows.append(row)
|
66 |
+
rows.reverse()
|
67 |
+
if len(rows) == 0:
|
68 |
+
return "no messages yet"
|
69 |
+
else:
|
70 |
+
html = "<div class='chatbot'>"
|
71 |
+
for row in rows:
|
72 |
+
html += "<div>"
|
73 |
+
html += f"<span>{row['inputs']}</span>"
|
74 |
+
html += f"<span class='outputs'>{row['outputs']}</span>"
|
75 |
+
html += "</div>"
|
76 |
+
html += "</div>"
|
77 |
+
return html
|
78 |
+
|
79 |
+
def store_message(name: str, message: str):
|
80 |
+
if name and message:
|
81 |
+
with open(DATA_FILE, "a") as csvfile:
|
82 |
+
writer = csv.DictWriter(csvfile, fieldnames=["name", "message", "time"])
|
83 |
+
writer.writerow(
|
84 |
+
{"name": name, "message": message, "time": str(datetime.now())}
|
85 |
+
)
|
86 |
+
commit_url = repo.push_to_hub()
|
87 |
+
return ""
|
88 |
+
|
89 |
+
iface = gr.Interface(
|
90 |
+
store_message,
|
91 |
+
[
|
92 |
+
inputs.Textbox(placeholder="Your name"),
|
93 |
+
inputs.Textbox(placeholder="Your message", lines=2),
|
94 |
+
],
|
95 |
+
"html",
|
96 |
+
css="""
|
97 |
+
.message {background-color:cornflowerblue;color:white; padding:4px;margin:4px;border-radius:4px; }
|
98 |
+
""",
|
99 |
+
)
|
100 |
+
|
101 |
+
#store_message(message, response) # Save to dataset
|
102 |
+
|
103 |
generator2 = gr.Interface.load("huggingface/EleutherAI/gpt-neo-2.7B")
|
104 |
generator3 = gr.Interface.load("huggingface/EleutherAI/gpt-j-6B")
|
105 |
generator1 = gr.Interface.load("huggingface/gpt2-large")
|
106 |
+
gr.Parallel(generator1,
|
107 |
+
generator2,
|
108 |
+
generator3,
|
109 |
+
inputs = gr.inputs.Textbox(lines=5, label="Enter a sentence to get another sentence."),
|
110 |
+
examples=examples
|
111 |
+
title="Mindfulness Story Generation with Persistent Dataset Memory",
|
112 |
+
description=f"Mindfulness Story Generation with Persistent Dataset Memory",
|
113 |
+
article=f"Memory Dataset URL: [{DATASET_REPO_URL}]({DATASET_REPO_URL})",
|
114 |
+
).launch(share=False)
|