openfree commited on
Commit
628b2cd
·
verified ·
1 Parent(s): 8528922

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -18
app.py CHANGED
@@ -258,31 +258,25 @@ def start_training(
258
  ## Your model is available at: <a href='https://huggingface.co/{username}/{slugged_lora_name}'>{username}/{slugged_lora_name}</a>"""
259
 
260
  def swap_visibilty(profile: Union[gr.OAuthProfile, None]):
261
- if is_spaces:
262
- if profile is None:
263
- return gr.update(elem_classes=["main_ui_logged_out"])
264
- else:
265
- return gr.update(elem_classes=["main_ui_logged_in"])
266
- else:
267
- return gr.update(elem_classes=["main_ui_logged_in"])
268
-
269
  def update_pricing(steps, oauth_token: Union[gr.OAuthToken, None]):
270
- if(oauth_token and is_spaces):
271
- user = whoami(oauth_token.token)
 
272
  seconds_per_iteration = 7.54
273
  total_seconds = (steps * seconds_per_iteration) + 240
274
  cost_per_second = 0.80/60/60
275
  cost = round(cost_per_second * total_seconds, 2)
276
  cost_preview = f'''To train this LoRA, a paid L4 GPU will be hooked under the hood during training and then removed once finished.
277
  ### Estimated to cost <b>< US$ {str(cost)}</b> for {round(int(total_seconds)/60, 2)} minutes with your current train settings <small>({int(steps)} iterations at {seconds_per_iteration}s/it)</small>'''
278
- if(user["canPay"]):
279
- return gr.update(visible=True), cost_preview, gr.update(visible=False), gr.update(visible=True)
280
- else:
281
- pay_disclaimer = f'''## ⚠️ {user["name"]}, your account doesn't have a payment method. Set one up <a href='https://huggingface.co/settings/billing/payment' target='_blank'>here</a> and come back here to train your LoRA<br><br>'''
282
- return gr.update(visible=True), pay_disclaimer+cost_preview, gr.update(visible=True), gr.update(visible=False)
283
- else:
284
  return gr.update(visible=False), "", gr.update(visible=False), gr.update(visible=True)
285
 
 
 
286
  def swap_base_model(model):
287
  return gr.update(visible=True) if model == "[dev] (high quality model, non-commercial license)" else gr.update(visible=False)
288
 
@@ -329,14 +323,14 @@ theme = gr.themes.Monochrome(
329
  text_size=gr.themes.Size(lg="18px", md="15px", sm="13px", xl="22px", xs="12px", xxl="24px", xxs="9px"),
330
  font=[gr.themes.GoogleFont("Source Sans Pro"), "ui-sans-serif", "system-ui", "sans-serif"],
331
  )
 
 
332
  css = """
333
  h1{font-size: 2em}
334
  h3{margin-top: 0}
335
  #component-1{text-align:center}
336
- .main_ui_logged_out{opacity: 0.3; pointer-events: none}
337
  .tabitem{border: 0px}
338
  .group_padding{padding: .55em}
339
- #space_model .wrap > label:last-child{opacity: 0.3; pointer-events:none}
340
  """
341
 
342
  # LoginButton 부분 제거
 
258
  ## Your model is available at: <a href='https://huggingface.co/{username}/{slugged_lora_name}'>{username}/{slugged_lora_name}</a>"""
259
 
260
  def swap_visibilty(profile: Union[gr.OAuthProfile, None]):
261
+ # HF_TOKEN이 있으므로 항상 로그인된 상태로 처리
262
+ return gr.update(elem_classes=["main_ui_logged_in"])
263
+
 
 
 
 
 
264
  def update_pricing(steps, oauth_token: Union[gr.OAuthToken, None]):
265
+ # HF_TOKEN을 사용하여 직접 확인
266
+ try:
267
+ user = whoami()
268
  seconds_per_iteration = 7.54
269
  total_seconds = (steps * seconds_per_iteration) + 240
270
  cost_per_second = 0.80/60/60
271
  cost = round(cost_per_second * total_seconds, 2)
272
  cost_preview = f'''To train this LoRA, a paid L4 GPU will be hooked under the hood during training and then removed once finished.
273
  ### Estimated to cost <b>< US$ {str(cost)}</b> for {round(int(total_seconds)/60, 2)} minutes with your current train settings <small>({int(steps)} iterations at {seconds_per_iteration}s/it)</small>'''
274
+ return gr.update(visible=True), cost_preview, gr.update(visible=False), gr.update(visible=True)
275
+ except:
 
 
 
 
276
  return gr.update(visible=False), "", gr.update(visible=False), gr.update(visible=True)
277
 
278
+
279
+
280
  def swap_base_model(model):
281
  return gr.update(visible=True) if model == "[dev] (high quality model, non-commercial license)" else gr.update(visible=False)
282
 
 
323
  text_size=gr.themes.Size(lg="18px", md="15px", sm="13px", xl="22px", xs="12px", xxl="24px", xxs="9px"),
324
  font=[gr.themes.GoogleFont("Source Sans Pro"), "ui-sans-serif", "system-ui", "sans-serif"],
325
  )
326
+
327
+
328
  css = """
329
  h1{font-size: 2em}
330
  h3{margin-top: 0}
331
  #component-1{text-align:center}
 
332
  .tabitem{border: 0px}
333
  .group_padding{padding: .55em}
 
334
  """
335
 
336
  # LoginButton 부분 제거