awacke1 commited on
Commit
df9b1b2
ยท
1 Parent(s): d82dee3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +2 -25
app.py CHANGED
@@ -6,17 +6,11 @@ import huggingface_hub
6
  from huggingface_hub import Repository, hf_hub_download, upload_file
7
  from datetime import datetime
8
 
9
- print("hfh", huggingface_hub.__version__)
10
-
11
  DATASET_REPO_URL = "https://huggingface.co/datasets/awacke1/data.csv"
12
  DATASET_REPO_ID = "awacke1/data.csv"
13
  DATA_FILENAME = "data.csv"
14
  DATA_FILE = os.path.join("data", DATA_FILENAME)
15
-
16
  HF_TOKEN = os.environ.get("HF_TOKEN")
17
- print("is none?", HF_TOKEN is None)
18
-
19
- print("hfh", huggingface_hub.__version__)
20
 
21
  # overriding/appending to the gradio template
22
  SCRIPT = """
@@ -31,7 +25,6 @@ if (!window.hasBeenRun) {
31
  with open(os.path.join(gr.networking.STATIC_TEMPLATE_LIB, "frontend", "index.html"), "a") as f:
32
  f.write(SCRIPT)
33
 
34
-
35
  try:
36
  hf_hub_download(
37
  repo_id=DATASET_REPO_ID,
@@ -40,8 +33,7 @@ try:
40
  force_filename=DATA_FILENAME
41
  )
42
  except:
43
- # file not found, we'll create it on the fly.
44
- print("file not found, probably")
45
 
46
  repo = Repository(
47
  local_dir="data", clone_from=DATASET_REPO_URL, use_auth_token=HF_TOKEN
@@ -66,7 +58,6 @@ def generate_html() -> str:
66
  html += "</div>"
67
  return html
68
 
69
-
70
  def store_message(name: str, message: str):
71
  if name and message:
72
  with open(DATA_FILE, "a") as csvfile:
@@ -74,23 +65,9 @@ def store_message(name: str, message: str):
74
  writer.writerow(
75
  {"name": name, "message": message, "time": str(datetime.now())}
76
  )
77
-
78
  commit_url = repo.push_to_hub()
79
- print(commit_url)
80
-
81
- #commit_url = upload_file(
82
- # DATA_FILE,
83
- # path_in_repo="data.csv",
84
- # repo_id=DATASET_REPO_ID,
85
- # repo_type='dataset',
86
- # token=HF_TOKEN,
87
- #)
88
-
89
- #print(commit_url)
90
-
91
  return generate_html()
92
 
93
-
94
  iface = gr.Interface(
95
  store_message,
96
  [
@@ -106,4 +83,4 @@ iface = gr.Interface(
106
  article=f"The dataset repo is [{DATASET_REPO_URL}]({DATASET_REPO_URL})",
107
  )
108
 
109
- iface.launch()
 
6
  from huggingface_hub import Repository, hf_hub_download, upload_file
7
  from datetime import datetime
8
 
 
 
9
  DATASET_REPO_URL = "https://huggingface.co/datasets/awacke1/data.csv"
10
  DATASET_REPO_ID = "awacke1/data.csv"
11
  DATA_FILENAME = "data.csv"
12
  DATA_FILE = os.path.join("data", DATA_FILENAME)
 
13
  HF_TOKEN = os.environ.get("HF_TOKEN")
 
 
 
14
 
15
  # overriding/appending to the gradio template
16
  SCRIPT = """
 
25
  with open(os.path.join(gr.networking.STATIC_TEMPLATE_LIB, "frontend", "index.html"), "a") as f:
26
  f.write(SCRIPT)
27
 
 
28
  try:
29
  hf_hub_download(
30
  repo_id=DATASET_REPO_ID,
 
33
  force_filename=DATA_FILENAME
34
  )
35
  except:
36
+ print("file not found")
 
37
 
38
  repo = Repository(
39
  local_dir="data", clone_from=DATASET_REPO_URL, use_auth_token=HF_TOKEN
 
58
  html += "</div>"
59
  return html
60
 
 
61
  def store_message(name: str, message: str):
62
  if name and message:
63
  with open(DATA_FILE, "a") as csvfile:
 
65
  writer.writerow(
66
  {"name": name, "message": message, "time": str(datetime.now())}
67
  )
 
68
  commit_url = repo.push_to_hub()
 
 
 
 
 
 
 
 
 
 
 
 
69
  return generate_html()
70
 
 
71
  iface = gr.Interface(
72
  store_message,
73
  [
 
83
  article=f"The dataset repo is [{DATASET_REPO_URL}]({DATASET_REPO_URL})",
84
  )
85
 
86
+ iface.launch()