pcuenq HF staff osanseviero commited on
Commit
32eaf3b
0 Parent(s):

Duplicate from osanseviero/persistent-data-final

Browse files

Co-authored-by: Omar Sanseviero <[email protected]>

Files changed (5) hide show
  1. .gitattributes +27 -0
  2. .gitignore +3 -0
  3. README.md +13 -0
  4. app.py +54 -0
  5. requirements.txt +2 -0
.gitattributes ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ *.7z filter=lfs diff=lfs merge=lfs -text
2
+ *.arrow filter=lfs diff=lfs merge=lfs -text
3
+ *.bin filter=lfs diff=lfs merge=lfs -text
4
+ *.bin.* filter=lfs diff=lfs merge=lfs -text
5
+ *.bz2 filter=lfs diff=lfs merge=lfs -text
6
+ *.ftz filter=lfs diff=lfs merge=lfs -text
7
+ *.gz filter=lfs diff=lfs merge=lfs -text
8
+ *.h5 filter=lfs diff=lfs merge=lfs -text
9
+ *.joblib filter=lfs diff=lfs merge=lfs -text
10
+ *.lfs.* filter=lfs diff=lfs merge=lfs -text
11
+ *.model filter=lfs diff=lfs merge=lfs -text
12
+ *.msgpack filter=lfs diff=lfs merge=lfs -text
13
+ *.onnx filter=lfs diff=lfs merge=lfs -text
14
+ *.ot filter=lfs diff=lfs merge=lfs -text
15
+ *.parquet filter=lfs diff=lfs merge=lfs -text
16
+ *.pb filter=lfs diff=lfs merge=lfs -text
17
+ *.pt filter=lfs diff=lfs merge=lfs -text
18
+ *.pth filter=lfs diff=lfs merge=lfs -text
19
+ *.rar filter=lfs diff=lfs merge=lfs -text
20
+ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
21
+ *.tar.* filter=lfs diff=lfs merge=lfs -text
22
+ *.tflite filter=lfs diff=lfs merge=lfs -text
23
+ *.tgz filter=lfs diff=lfs merge=lfs -text
24
+ *.xz filter=lfs diff=lfs merge=lfs -text
25
+ *.zip filter=lfs diff=lfs merge=lfs -text
26
+ *.zstandard filter=lfs diff=lfs merge=lfs -text
27
+ *tfevents* filter=lfs diff=lfs merge=lfs -text
.gitignore ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ .env/
2
+ data/
3
+ .vscode/
README.md ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: Persistent Data
3
+ emoji: 🐨
4
+ colorFrom: pink
5
+ colorTo: gray
6
+ sdk: gradio
7
+ sdk_version: 3.35.2
8
+ app_file: app.py
9
+ pinned: false
10
+ duplicated_from: osanseviero/persistent-data-final
11
+ ---
12
+
13
+ # Configuration
app.py ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import csv
3
+ import gradio as gr
4
+ from gradio import inputs, outputs
5
+ from datetime import datetime
6
+
7
+ DATA_FILENAME = "data.csv"
8
+ DATA_FILE = os.path.join("/data", DATA_FILENAME)
9
+
10
+ def generate_html() -> str:
11
+ with open(DATA_FILE) as csvfile:
12
+ reader = csv.reader(csvfile)
13
+ rows = []
14
+ for row in reader:
15
+ print(row)
16
+ rows.append(row)
17
+ print(rows)
18
+ if len(rows) == 0:
19
+ return "no messages yet"
20
+ else:
21
+ html = "<div class='chatbot'>"
22
+ print(row)
23
+ for row in rows:
24
+ html += "<div>"
25
+ html += f"<span>{row[0]}</span>"
26
+ html += f"<span class='message'>{row[1]}</span>"
27
+ html += "</div>"
28
+ html += "</div>"
29
+ return html
30
+
31
+
32
+ def store_message(name: str, message: str):
33
+ if name and message:
34
+ with open(DATA_FILE, "a") as csvfile:
35
+ csv.writer(csvfile).writerow([name, message])
36
+
37
+ return generate_html()
38
+
39
+
40
+ iface = gr.Interface(
41
+ store_message,
42
+ [
43
+ inputs.Textbox(placeholder="Your name"),
44
+ inputs.Textbox(placeholder="Your message", lines=2),
45
+ ],
46
+ "html",
47
+ css="""
48
+ .message {background-color:cornflowerblue;color:white; padding:4px;margin:4px;border-radius:4px; }
49
+ """,
50
+ title="Reading/writing to persistent storage within the Space",
51
+ description=f"This is a demo of how to do simple *shared data persistence* in a Gradio Space, backed in the storage of a Space (/data directory).",
52
+ )
53
+
54
+ iface.launch()
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ Werkzeug==2.0.3
2
+ huggingface_hub==0.4.0