multimodalart HF staff commited on
Commit
5e31c93
1 Parent(s): fb17b10

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +3 -15
app.py CHANGED
@@ -65,9 +65,8 @@ def download_file(url, filename, folder="."):
65
  response.raise_for_status()
66
  with open(f"{folder}/{filename}", 'wb') as f:
67
  f.write(response.content)
68
- print(f"{filename} downloaded.")
69
  except requests.exceptions.RequestException as e:
70
- print(f"Error downloading file: {e}")
71
 
72
  def process_url(url, do_download=True, folder="."):
73
  json_data = get_json_data(url)
@@ -124,12 +123,8 @@ def upload_civit_to_hf(profile: Optional[gr.OAuthProfile], url, progress=gr.Prog
124
 
125
  folder = str(uuid.uuid4())
126
  os.makedirs(folder, exist_ok=False)
127
- info, downloaded_files = process_url(url, folder)
128
- create_readme(info, downloaded_files, folder)
129
- print(os.path.abspath("."))
130
- print(os.listdir("."))
131
- print(os.path.abspath(folder))
132
- print(os.listdir(folder))
133
  try:
134
  api = HfApi(token=os.environ["HUGGING_FACE_HUB_TOKEN"])
135
  username = api.whoami()["name"]
@@ -144,7 +139,6 @@ def upload_civit_to_hf(profile: Optional[gr.OAuthProfile], url, progress=gr.Prog
144
  transfer_repos = gr.load("multimodalart/transfer_repos", hf_token=os.environ["HUGGING_FACE_HUB_TOKEN"], src="spaces")
145
  user_repo_id = f"{profile.preferred_username}/{slug_name}"
146
  response_code = transfer_repos(repo_id, user_repo_id)
147
- print("response_code", response_code)
148
  i = 0
149
  while response_code != "200":
150
  if response_code == "404":
@@ -190,12 +184,10 @@ def get_creator(username):
190
  def extract_huggingface_username(username):
191
  data = get_creator(username)
192
  links = data.get('result', {}).get('data', {}).get('json', {}).get('links', [])
193
- print(links)
194
  for link in links:
195
  url = link.get('url', '')
196
  if url.startswith('https://huggingface.co/') or url.startswith('https://www.huggingface.co/'):
197
  username = url.split('/')[-1]
198
- print("Extracted username:", username)
199
  return username
200
 
201
  return None
@@ -204,11 +196,7 @@ def extract_huggingface_username(username):
204
  def check_civit_link(profile: Optional[gr.OAuthProfile], url):
205
  info, _ = process_url(url, do_download=False)
206
  hf_username = extract_huggingface_username(info['creator'])
207
- print(hf_username)
208
  attributes_methods = dir(profile)
209
- for attribute in attributes_methods:
210
- if not attribute.startswith('__'):
211
- print(f"{attribute}: {getattr(profile, attribute)}")
212
  if(not hf_username):
213
  no_username_text = 'Oops, your CivitAI profile seems to not have information about your Hugging Face account. Please visit <a href="https://civitai.com/user/account">https://civitai.com/user/account</a> and include it there<br><img width="60%" src="https://i.imgur.com/hCbo9uL.png" />'
214
  return no_username_text, gr.update(), gr.update(visible=True)
 
65
  response.raise_for_status()
66
  with open(f"{folder}/{filename}", 'wb') as f:
67
  f.write(response.content)
 
68
  except requests.exceptions.RequestException as e:
69
+ raise gr.Error(f"Error downloading file: {e}")
70
 
71
  def process_url(url, do_download=True, folder="."):
72
  json_data = get_json_data(url)
 
123
 
124
  folder = str(uuid.uuid4())
125
  os.makedirs(folder, exist_ok=False)
126
+ info, downloaded_files = process_url(url, folder=folder)
127
+ create_readme(info, downloaded_files, folder=folder)
 
 
 
 
128
  try:
129
  api = HfApi(token=os.environ["HUGGING_FACE_HUB_TOKEN"])
130
  username = api.whoami()["name"]
 
139
  transfer_repos = gr.load("multimodalart/transfer_repos", hf_token=os.environ["HUGGING_FACE_HUB_TOKEN"], src="spaces")
140
  user_repo_id = f"{profile.preferred_username}/{slug_name}"
141
  response_code = transfer_repos(repo_id, user_repo_id)
 
142
  i = 0
143
  while response_code != "200":
144
  if response_code == "404":
 
184
  def extract_huggingface_username(username):
185
  data = get_creator(username)
186
  links = data.get('result', {}).get('data', {}).get('json', {}).get('links', [])
 
187
  for link in links:
188
  url = link.get('url', '')
189
  if url.startswith('https://huggingface.co/') or url.startswith('https://www.huggingface.co/'):
190
  username = url.split('/')[-1]
 
191
  return username
192
 
193
  return None
 
196
  def check_civit_link(profile: Optional[gr.OAuthProfile], url):
197
  info, _ = process_url(url, do_download=False)
198
  hf_username = extract_huggingface_username(info['creator'])
 
199
  attributes_methods = dir(profile)
 
 
 
200
  if(not hf_username):
201
  no_username_text = 'Oops, your CivitAI profile seems to not have information about your Hugging Face account. Please visit <a href="https://civitai.com/user/account">https://civitai.com/user/account</a> and include it there<br><img width="60%" src="https://i.imgur.com/hCbo9uL.png" />'
202
  return no_username_text, gr.update(), gr.update(visible=True)