muellerzr HF staff commited on
Commit
4f92044
1 Parent(s): 5eb5b16

User token

Browse files
Files changed (1) hide show
  1. app.py +5 -2
app.py CHANGED
@@ -12,6 +12,7 @@ from accelerate.utils import convert_bytes, calculate_maximum_sizes
12
  HAS_DISCUSSION = True
13
  MODEL_NAME = None
14
  LIBRARY = None
 
15
  TOKEN = os.environ.get("HUGGINGFACE_API_LOGIN", None)
16
 
17
  def check_for_discussion(model_name:str):
@@ -23,9 +24,10 @@ def check_for_discussion(model_name:str):
23
 
24
  def report_results():
25
  "Reports the results of a memory calculation to the model's discussion page, and opens a new tab to it afterwards"
26
- global MODEL_NAME, LIBRARY, TOKEN
27
  api = HfApi(token=TOKEN)
28
- results = calculate_memory(MODEL_NAME, LIBRARY, ["fp32", "fp16", "int8", "int4"], raw=True)
 
29
  post = f"""# Model Memory Requirements\n
30
 
31
  These calculations were measured from the [Model Memory Utility Space](https://hf.co/spaces/hf-accelerate/model-memory-utility) on the Hub.
@@ -149,6 +151,7 @@ with gr.Blocks() as demo:
149
  with gr.Row():
150
  btn = gr.Button("Calculate Memory Usage")
151
  post_to_hub = gr.Button(value = "Report results in this model repo's discussions!\n(Will open in a new tab)", visible=False)
 
152
 
153
  btn.click(
154
  calculate_memory, inputs=[inp, library, options, access_token], outputs=[out_text, out, post_to_hub],
 
12
  HAS_DISCUSSION = True
13
  MODEL_NAME = None
14
  LIBRARY = None
15
+ USER_TOKEN = None
16
  TOKEN = os.environ.get("HUGGINGFACE_API_LOGIN", None)
17
 
18
  def check_for_discussion(model_name:str):
 
24
 
25
  def report_results():
26
  "Reports the results of a memory calculation to the model's discussion page, and opens a new tab to it afterwards"
27
+ global MODEL_NAME, LIBRARY, TOKEN, USER_TOKEN
28
  api = HfApi(token=TOKEN)
29
+ results = calculate_memory(MODEL_NAME, LIBRARY, ["fp32", "fp16", "int8", "int4"], access_token=USER_TOKEN, raw=True)
30
+ USER_TOKEN = None
31
  post = f"""# Model Memory Requirements\n
32
 
33
  These calculations were measured from the [Model Memory Utility Space](https://hf.co/spaces/hf-accelerate/model-memory-utility) on the Hub.
 
151
  with gr.Row():
152
  btn = gr.Button("Calculate Memory Usage")
153
  post_to_hub = gr.Button(value = "Report results in this model repo's discussions!\n(Will open in a new tab)", visible=False)
154
+ USER_TOKEN = access_token
155
 
156
  btn.click(
157
  calculate_memory, inputs=[inp, library, options, access_token], outputs=[out_text, out, post_to_hub],