Matthias Kleiner commited on
Commit
b9923b7
1 Parent(s): 9634f2d

fixed filepaths

Browse files
Files changed (1) hide show
  1. app.py +16 -8
app.py CHANGED
@@ -5,6 +5,8 @@ import datetime
5
  from huggingface_hub import hf_api, CommitScheduler, HfApi
6
  from pathlib import Path
7
 
 
 
8
  feedback_file = Path("output_data/") / f"output_{uuid.uuid4()}.json"
9
  feedback_folder = feedback_file.parent
10
 
@@ -40,7 +42,11 @@ def func(file, number_of_pages, secret):
40
  date_string = datetime.datetime.now().strftime("%Y-%m-%d-%H-%M-%S")
41
 
42
  print(file)
43
- unique_filename = f"{file.split('.')[0]}_{date_string}.{file.split('.')[-1]}"
 
 
 
 
44
 
45
  print(unique_filename)
46
 
@@ -53,12 +59,12 @@ def func(file, number_of_pages, secret):
53
  )
54
 
55
 
56
- space_runtime = hf_api.get_space_runtime("ByMatthew/deckify_private", token=read_key)
57
  print(f"Space runtime: {space_runtime}")
58
 
59
  if not space_runtime.stage == "RUNNING": # might need to check lowercase or something
60
 
61
- space_runtime_after_restart = hf_api.restart_space("ByMatthew/deckify_private", token=read_key)
62
  print(f"Space runtime after restart: {space_runtime_after_restart}")
63
 
64
 
@@ -66,7 +72,7 @@ def func(file, number_of_pages, secret):
66
  retry_delay = 10
67
  success = False
68
  for i in range(max_retries):
69
- space_runtime = hf_api.get_space_runtime("ByMatthew/deckify_private", token=read_key)
70
  print(f"Space runtime: {space_runtime}")
71
  if space_runtime.stage == "RUNNING":
72
  success = True
@@ -76,7 +82,7 @@ def func(file, number_of_pages, secret):
76
  if not success:
77
  return "Failed to start the private space in time. Please try again later."
78
 
79
- client = Client("ByMatthew/deckify_private", hf_token=read_key)
80
 
81
  print(f"Client: {client}")
82
 
@@ -88,13 +94,15 @@ def func(file, number_of_pages, secret):
88
  # s = "".join([str(random.randint(0, 9)) for i in range(10)])
89
  # with open(f"{s}.tex", "w", encoding="utf-8") as f:
90
  # f.write(text)
 
 
 
91
 
92
  temp_string = "% The following slides are generated with [[SCIDECK]](https://huggingface.co/spaces/ByMatthew/Scideck)"
93
  temp_string += "\n% Generated on " + date_string
94
  temp_string += "\n%" + "-"*100 + "\n"
95
  output = temp_string + output
96
 
97
- save_output(unique_filename, output, number_of_pages, date_string)
98
 
99
  return output
100
 
@@ -151,8 +159,8 @@ if __name__ == "__main__":
151
  number_of_pages = gr.Number(label="Number of pages")
152
  secret = gr.Textbox(label="Password", type="password")
153
  output = gr.Textbox(label="Output", show_copy_button=True, interactive=False)
154
- greet_btn = gr.Button("Generate slides")
155
- greet_btn.click(fn=func, inputs=[upload_button, number_of_pages, secret], outputs=output, api_name="greet")
156
 
157
  demo.queue(max_size=5)
158
  demo.launch()
 
5
  from huggingface_hub import hf_api, CommitScheduler, HfApi
6
  from pathlib import Path
7
 
8
+ deckify_private = "ByMatthew/deckify_private"
9
+
10
  feedback_file = Path("output_data/") / f"output_{uuid.uuid4()}.json"
11
  feedback_folder = feedback_file.parent
12
 
 
42
  date_string = datetime.datetime.now().strftime("%Y-%m-%d-%H-%M-%S")
43
 
44
  print(file)
45
+ # use only the filename form an absolute path basename
46
+ dir, filename = os.path.split(file)
47
+ print(f"dir: {dir}, filename: {filename}")
48
+
49
+ unique_filename = f"{filename.split('.')[0]}_{date_string}.{filename.split('.')[-1]}"
50
 
51
  print(unique_filename)
52
 
 
59
  )
60
 
61
 
62
+ space_runtime = hf_api.get_space_runtime(deckify_private, token=read_key)
63
  print(f"Space runtime: {space_runtime}")
64
 
65
  if not space_runtime.stage == "RUNNING": # might need to check lowercase or something
66
 
67
+ space_runtime_after_restart = hf_api.restart_space(deckify_private, token=read_key)
68
  print(f"Space runtime after restart: {space_runtime_after_restart}")
69
 
70
 
 
72
  retry_delay = 10
73
  success = False
74
  for i in range(max_retries):
75
+ space_runtime = hf_api.get_space_runtime(deckify_private, token=read_key)
76
  print(f"Space runtime: {space_runtime}")
77
  if space_runtime.stage == "RUNNING":
78
  success = True
 
82
  if not success:
83
  return "Failed to start the private space in time. Please try again later."
84
 
85
+ client = Client(deckify_private, hf_token=read_key)
86
 
87
  print(f"Client: {client}")
88
 
 
94
  # s = "".join([str(random.randint(0, 9)) for i in range(10)])
95
  # with open(f"{s}.tex", "w", encoding="utf-8") as f:
96
  # f.write(text)
97
+
98
+
99
+ save_output(unique_filename, output, number_of_pages, date_string)
100
 
101
  temp_string = "% The following slides are generated with [[SCIDECK]](https://huggingface.co/spaces/ByMatthew/Scideck)"
102
  temp_string += "\n% Generated on " + date_string
103
  temp_string += "\n%" + "-"*100 + "\n"
104
  output = temp_string + output
105
 
 
106
 
107
  return output
108
 
 
159
  number_of_pages = gr.Number(label="Number of pages")
160
  secret = gr.Textbox(label="Password", type="password")
161
  output = gr.Textbox(label="Output", show_copy_button=True, interactive=False)
162
+ genereate_slides_btn = gr.Button("Generate slides")
163
+ genereate_slides_btn.click(fn=func, inputs=[upload_button, number_of_pages, secret], outputs=output, api_name="genereate_slides")
164
 
165
  demo.queue(max_size=5)
166
  demo.launch()