kbourne commited on
Commit
f6535d5
verified
1 Parent(s): a91c0cc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +1 -136
app.py CHANGED
@@ -7,141 +7,6 @@ import huggingface_hub
7
  from huggingface_hub import Repository
8
  from datetime import datetime
9
 
10
- # example of secret access
11
- # spreadsheet = os.environ['spreadsheet']
12
- # st.write(f"Spreadsheet: {spreadsheet}")
13
-
14
- # Create a connection object.
15
- # conn = st.connection("gsheets", type=GSheetsConnection)
16
-
17
- # df = conn.read(spreadsheet=spreadsheet, usecols=[0, 1])
18
-
19
- # data = conn.read(spreadsheet=spreadsheet, usecols=[0, 1])
20
- # st.write(f"Spreadsheet connected: {spreadsheet}")
21
- # st.dataframe(data)
22
-
23
- # Print results.
24
- # for row in df.itertuples():
25
- # st.write(f"{row.name} has a :{row.pet}:")
26
-
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") # os.environ['HF_TOKEN'] #
41
- print("is none?", HF_TOKEN is None)
42
-
43
- print("hfh", huggingface_hub.__version__)
44
-
45
- repo = Repository(
46
- local_dir="data", clone_from=DATASET_REPO_URL, use_auth_token=HF_TOKEN
47
- )
48
- print("repo connection: ", repo)
49
-
50
- name = "bot"
51
- message = "beep boop"
52
-
53
- with open(DATA_FILE, "a") as csvfile:
54
- writer = csv.DictWriter(csvfile, fieldnames=["name", "message", "time"])
55
- writer.writerow(
56
- {"name": name, "message": message, "time": str(datetime.now())}
57
- )
58
- print(f"writing in: name: {name} message: {message}")
59
- commit_url = repo.push_to_hub()
60
- print(f"commit_url: ", commit_url)
61
-
62
-
63
- # def store_message(name: str, message: str):
64
- # if name and message:
65
- # with open(DATA_FILE, "a") as csvfile:
66
- # writer = csv.DictWriter(csvfile, fieldnames=["name", "message", "time"])
67
- # writer.writerow(
68
- # {"name": name, "message": message, "time": str(datetime.now())}
69
- # )
70
- # commit_url = repo.push_to_hub()
71
- # print(commit_url)
72
-
73
- # return generate_html()
74
-
75
- # Create or clone a repo using Repository app.py 路 julien-c/persistent-data at main 5.
76
- # These methods use a token HF_TOKEN which is passed as a secret from the Hub.
77
- # Note that they also specify a local directory.
78
-
79
- # Save your data in the directory from above. E.g. the first space 5 is appending the data to a csv.
80
-
81
- # # overriding/appending to the gradio template
82
- # SCRIPT = """
83
- # <script>
84
- # if (!window.hasBeenRun) {
85
- # window.hasBeenRun = true;
86
- # console.log("should only happen once");
87
- # document.querySelector("button.submit").click();
88
- # }
89
- # </script>
90
- # """
91
- # with open(os.path.join(gr.networking.STATIC_TEMPLATE_LIB, "frontend", "index.html"), "a") as f:
92
- # f.write(SCRIPT)
93
-
94
- # repo = Repository(
95
- # local_dir="data", clone_from=DATASET_REPO_URL, use_auth_token=HF_TOKEN
96
- # )
97
-
98
-
99
- # def generate_html() -> str:
100
- # with open(DATA_FILE) as csvfile:
101
- # reader = csv.DictReader(csvfile)
102
- # rows = []
103
- # for row in reader:
104
- # rows.append(row)
105
- # rows.reverse()
106
- # if len(rows) == 0:
107
- # return "no messages yet"
108
- # else:
109
- # html = "<div class='chatbot'>"
110
- # for row in rows:
111
- # html += "<div>"
112
- # html += f"<span>{row['name']}</span>"
113
- # html += f"<span class='message'>{row['message']}</span>"
114
- # html += "</div>"
115
- # html += "</div>"
116
- # return html
117
-
118
-
119
- # def store_message(name: str, message: str):
120
- # if name and message:
121
- # with open(DATA_FILE, "a") as csvfile:
122
- # writer = csv.DictWriter(csvfile, fieldnames=["name", "message", "time"])
123
- # writer.writerow(
124
- # {"name": name, "message": message, "time": str(datetime.now())}
125
- # )
126
- # commit_url = repo.push_to_hub()
127
- # print(commit_url)
128
-
129
- # return generate_html()
130
-
131
-
132
- # iface = gr.Interface(
133
- # store_message,
134
- # [
135
- # inputs.Textbox(placeholder="Your name"),
136
- # inputs.Textbox(placeholder="Your message", lines=2),
137
- # ],
138
- # "html",
139
- # css="""
140
- # .message {background-color:cornflowerblue;color:white; padding:4px;margin:4px;border-radius:4px; }
141
- # """,
142
- # title="Reading/writing to a HuggingFace dataset repo from Spaces",
143
- # description=f"This is a demo of how to do simple *shared data persistence* in a Gradio Space, backed by a dataset repo.",
144
- # article=f"The dataset repo is [{DATASET_REPO_URL}]({DATASET_REPO_URL}) (open in new tab)",
145
- # )
146
-
147
- # iface.launch()
 
7
  from huggingface_hub import Repository
8
  from datetime import datetime
9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
  st.title("Basic Streamlit App")
11
  name = st.text_input("Enter your name", '')
12
+ st.write(f"Salutations {name}!")