awacke1 commited on
Commit
7761a37
ยท
1 Parent(s): 9cae1de

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -25
app.py CHANGED
@@ -3,15 +3,11 @@ import csv
3
  import gradio as gr
4
  from gradio import inputs, outputs
5
  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
  DATA_FILENAME = "data.csv"
13
- #DATA_FILE = os.path.join(DATA_DIRNAME, DATA_FILENAME)
14
- #DATA_DIRNAME = "data"
15
  DATA_FILE = os.path.join("data", DATA_FILENAME)
16
 
17
  HF_TOKEN = os.environ.get("HF_TOKEN")
@@ -33,16 +29,6 @@ with open(os.path.join(gr.networking.STATIC_TEMPLATE_LIB, "frontend", "index.htm
33
  f.write(SCRIPT)
34
 
35
 
36
- try:
37
- hf_hub_download(
38
- repo_id=DATASET_REPO_ID,
39
- filename=DATA_FILENAME,
40
- cache_dir=DATA_DIRNAME,
41
- force_filename=DATA_FILENAME
42
- )
43
- except:
44
- # file not found, we'll create it on the fly.
45
- print("file not found, probably")
46
 
47
  repo = Repository(
48
  local_dir="data", clone_from=DATASET_REPO_URL, use_auth_token=HF_TOKEN
@@ -76,13 +62,7 @@ def store_message(name: str, message: str):
76
  writer.writerow(
77
  {"name": name, "message": message, "time": str(datetime.now())}
78
  )
79
- commit_url = upload_file(
80
- DATA_FILE,
81
- path_in_repo=DATA_FILENAME,
82
- repo_id=DATASET_REPO_ID,
83
- token=HF_TOKEN,
84
- )
85
-
86
  print(commit_url)
87
 
88
  return generate_html()
@@ -100,7 +80,7 @@ iface = gr.Interface(
100
  """,
101
  title="Reading/writing to a HuggingFace dataset repo from Spaces",
102
  description=f"This is a demo of how to do simple *shared data persistence* in a Gradio Space, backed by a dataset repo.",
103
- article=f"The dataset repo is [{DATASET_REPO_URL}]({DATASET_REPO_URL})",
104
  )
105
 
106
- iface.launch()
 
3
  import gradio as gr
4
  from gradio import inputs, outputs
5
  import huggingface_hub
6
+ from huggingface_hub import Repository
7
  from datetime import datetime
8
 
9
+ DATASET_REPO_URL = "https://huggingface.co/datasets/awacke1"
 
 
10
  DATA_FILENAME = "data.csv"
 
 
11
  DATA_FILE = os.path.join("data", DATA_FILENAME)
12
 
13
  HF_TOKEN = os.environ.get("HF_TOKEN")
 
29
  f.write(SCRIPT)
30
 
31
 
 
 
 
 
 
 
 
 
 
 
32
 
33
  repo = Repository(
34
  local_dir="data", clone_from=DATASET_REPO_URL, use_auth_token=HF_TOKEN
 
62
  writer.writerow(
63
  {"name": name, "message": message, "time": str(datetime.now())}
64
  )
65
+ commit_url = repo.push_to_hub()
 
 
 
 
 
 
66
  print(commit_url)
67
 
68
  return generate_html()
 
80
  """,
81
  title="Reading/writing to a HuggingFace dataset repo from Spaces",
82
  description=f"This is a demo of how to do simple *shared data persistence* in a Gradio Space, backed by a dataset repo.",
83
+ article=f"The dataset repo is [{DATASET_REPO_URL}]({DATASET_REPO_URL}) (open in new tab)",
84
  )
85
 
86
+ iface.launch()