Keith Bourne commited on
Commit
e4def22
·
1 Parent(s): 5e07d80

Add more GS code 7

Browse files
Files changed (1) hide show
  1. app.py +82 -1
app.py CHANGED
@@ -1,7 +1,6 @@
1
 
2
  import streamlit as st
3
  import pandas as pd
4
- # from streamlit_gsheets import GSheetsConnection
5
  import os
6
  import csv
7
  import huggingface_hub
@@ -28,3 +27,85 @@ from datetime import datetime
28
  st.title("Basic Streamlit App")
29
  name = st.text_input("Enter your name", '')
30
  st.write(f"Salutations {name}!")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
 
2
  import streamlit as st
3
  import pandas as pd
 
4
  import os
5
  import csv
6
  import huggingface_hub
 
27
  st.title("Basic Streamlit App")
28
  name = st.text_input("Enter your name", '')
29
  st.write(f"Salutations {name}!")
30
+
31
+ # https://huggingface.co/datasets/kbourne/first_dataset
32
+ # https://huggingface.co/datasets/julien-c/persistent-space-dataset
33
+ DATASET_REPO_URL = "https://huggingface.co/datasets/kbourne/first_dataset"
34
+ st.write(f"DATASET_REPO_URL: {DATASET_REPO_URL}")
35
+
36
+ DATA_FILENAME = "data.csv"
37
+ DATA_FILE = os.path.join("data", DATA_FILENAME)
38
+ st.write(f"DATA_FILENAME: {DATA_FILENAME}")
39
+
40
+ HF_TOKEN = os.environ.get("HF_TOKEN")
41
+ print("is none?", HF_TOKEN is None)
42
+
43
+ print("hfh", huggingface_hub.__version__)
44
+
45
+ # overriding/appending to the gradio template
46
+ SCRIPT = """
47
+ <script>
48
+ if (!window.hasBeenRun) {
49
+ window.hasBeenRun = true;
50
+ console.log("should only happen once");
51
+ document.querySelector("button.submit").click();
52
+ }
53
+ </script>
54
+ """
55
+ with open(os.path.join(gr.networking.STATIC_TEMPLATE_LIB, "frontend", "index.html"), "a") as f:
56
+ f.write(SCRIPT)
57
+
58
+ repo = Repository(
59
+ local_dir="data", clone_from=DATASET_REPO_URL, use_auth_token=HF_TOKEN
60
+ )
61
+
62
+
63
+ # def generate_html() -> str:
64
+ # with open(DATA_FILE) as csvfile:
65
+ # reader = csv.DictReader(csvfile)
66
+ # rows = []
67
+ # for row in reader:
68
+ # rows.append(row)
69
+ # rows.reverse()
70
+ # if len(rows) == 0:
71
+ # return "no messages yet"
72
+ # else:
73
+ # html = "<div class='chatbot'>"
74
+ # for row in rows:
75
+ # html += "<div>"
76
+ # html += f"<span>{row['name']}</span>"
77
+ # html += f"<span class='message'>{row['message']}</span>"
78
+ # html += "</div>"
79
+ # html += "</div>"
80
+ # return html
81
+
82
+
83
+ # def store_message(name: str, message: str):
84
+ # if name and message:
85
+ # with open(DATA_FILE, "a") as csvfile:
86
+ # writer = csv.DictWriter(csvfile, fieldnames=["name", "message", "time"])
87
+ # writer.writerow(
88
+ # {"name": name, "message": message, "time": str(datetime.now())}
89
+ # )
90
+ # commit_url = repo.push_to_hub()
91
+ # print(commit_url)
92
+
93
+ # return generate_html()
94
+
95
+
96
+ # iface = gr.Interface(
97
+ # store_message,
98
+ # [
99
+ # inputs.Textbox(placeholder="Your name"),
100
+ # inputs.Textbox(placeholder="Your message", lines=2),
101
+ # ],
102
+ # "html",
103
+ # css="""
104
+ # .message {background-color:cornflowerblue;color:white; padding:4px;margin:4px;border-radius:4px; }
105
+ # """,
106
+ # title="Reading/writing to a HuggingFace dataset repo from Spaces",
107
+ # description=f"This is a demo of how to do simple *shared data persistence* in a Gradio Space, backed by a dataset repo.",
108
+ # article=f"The dataset repo is [{DATASET_REPO_URL}]({DATASET_REPO_URL}) (open in new tab)",
109
+ # )
110
+
111
+ # iface.launch()