seawolf2357 commited on
Commit
e793cbe
ยท
verified ยท
1 Parent(s): 9837785

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -35
app.py CHANGED
@@ -494,6 +494,7 @@ with gr.Blocks(title="{repo_name}") as demo:
494
  if __name__ == "__main__":
495
  demo.launch()
496
  '''
 
497
  app_code = f'''import gradio as gr
498
  from PIL import Image
499
  import numpy as np
@@ -830,11 +831,12 @@ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-
830
  """
831
  readme_path.write_text(readme_content, encoding="utf-8")
832
  yield "โœ… README.md created/updated"
833
- # ์Šค๋งˆํŠธ ์ƒ์„ฑ์ด ๋น„ํ™œ์„ฑํ™”๋œ ๊ฒฝ์šฐ์—๋„ README.md ํ™•์ธ ๋ฐ ์ƒ์„ฑ
834
- readme_path = Path(folder) / "README.md"
835
- if not readme_path.exists():
836
- # ๊ธฐ๋ณธ README.md ์ƒ์„ฑ
837
- readme_content = f"""---
 
838
  title: {repo_hf.replace("-", " ").title()}
839
  emoji: ๐Ÿš€
840
  colorFrom: blue
@@ -851,8 +853,8 @@ Deployed from: {repo_git}
851
 
852
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
853
  """
854
- readme_path.write_text(readme_content, encoding="utf-8")
855
- yield "โœ… README.md created with required configuration"
856
 
857
  # requirements.txt ํ™•์ธ ๋ฐ ๋ฌธ์ œ ํ•ด๊ฒฐ
858
  req_path = Path(folder) / "requirements.txt"
@@ -1089,6 +1091,9 @@ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-
1089
  yaml_header = parts[1]
1090
  content = parts[2]
1091
 
 
 
 
1092
  local_guide = f"""
1093
  ## โš ๏ธ GPU/CUDA Requirements
1094
 
@@ -1127,7 +1132,9 @@ To use GPU on this Space:
1127
  yield "๐Ÿ“ Added GPU setup guide to README.md"
1128
  except Exception as e:
1129
  yield f"โš ๏ธ Could not update README with GPU guide: {str(e)}"
1130
-
 
 
1131
  # Remove .git directory to save space and avoid issues
1132
  git_dir = os.path.join(folder, '.git')
1133
  if os.path.exists(git_dir):
@@ -1178,12 +1185,6 @@ pinned: false
1178
  except Exception as e:
1179
  yield f"โš ๏ธ Could not update README.md: {str(e)}"
1180
 
1181
- # Remove .git directory to save space and avoid issues
1182
- git_dir = os.path.join(folder, '.git')
1183
- if os.path.exists(git_dir):
1184
- shutil.rmtree(git_dir)
1185
- yield "๐Ÿงน Removed .git directory"
1186
-
1187
  # Create the HuggingFace repo with retries
1188
  yield "๐Ÿ—๏ธ Creating Hugging Face Space..."
1189
 
@@ -1239,12 +1240,6 @@ pinned: false
1239
  if not space_created:
1240
  raise Exception("Failed to create space")
1241
 
1242
- # Check folder size
1243
- except Exception as e:
1244
- yield f"โš ๏ธ Warning during space creation: {str(e)}"
1245
- # ๊ณ„์† ์ง„ํ–‰ํ•˜์ง€ ์•Š๊ณ  ์˜ค๋ฅ˜ ๋ฐœ์ƒ
1246
- raise
1247
-
1248
  # Check folder size
1249
  folder_size = sum(os.path.getsize(os.path.join(dirpath, filename))
1250
  for dirpath, dirnames, filenames in os.walk(folder)
@@ -1346,20 +1341,6 @@ pinned: false
1346
 
1347
  if not upload_success:
1348
  raise Exception("Upload failed after all retries")
1349
- except Exception as upload_error:
1350
- # If upload fails, try to give more specific error info
1351
- error_msg = str(upload_error)
1352
- if "LFS pointer" in error_msg:
1353
- yield "โŒ Upload failed due to remaining LFS pointer files"
1354
- yield "๐Ÿ” Searching for remaining LFS pointers..."
1355
-
1356
- # Do another scan for LFS files
1357
- for root, dirs, files in os.walk(folder):
1358
- for file in files:
1359
- filepath = os.path.join(root, file)
1360
- if is_lfs_pointer_file(filepath):
1361
- yield f" Found LFS pointer: {filepath.replace(folder + os.sep, '')}"
1362
- raise upload_error
1363
 
1364
  # Clean up the temporary folder
1365
  shutil.rmtree(folder)
@@ -1398,7 +1379,7 @@ pinned: false
1398
  yield "\n๐Ÿค– **Smart Generation**: An AI-generated Gradio interface was created based on repository analysis"
1399
 
1400
  # ์ถ”๊ฐ€ ์•ˆ๋‚ด์‚ฌํ•ญ
1401
- if any(dep.startswith("git+") for dep in analysis.get("dependencies", [])):
1402
  yield "\nโš ๏ธ **Build Notice**: This repository contains git dependencies that may take longer to build"
1403
 
1404
  except subprocess.CalledProcessError as e:
 
494
  if __name__ == "__main__":
495
  demo.launch()
496
  '''
497
+ elif has_cv:
498
  app_code = f'''import gradio as gr
499
  from PIL import Image
500
  import numpy as np
 
831
  """
832
  readme_path.write_text(readme_content, encoding="utf-8")
833
  yield "โœ… README.md created/updated"
834
+ else:
835
+ # ์Šค๋งˆํŠธ ์ƒ์„ฑ์ด ๋น„ํ™œ์„ฑํ™”๋œ ๊ฒฝ์šฐ์—๋„ README.md ํ™•์ธ ๋ฐ ์ƒ์„ฑ
836
+ readme_path = Path(folder) / "README.md"
837
+ if not readme_path.exists():
838
+ # ๊ธฐ๋ณธ README.md ์ƒ์„ฑ
839
+ readme_content = f"""---
840
  title: {repo_hf.replace("-", " ").title()}
841
  emoji: ๐Ÿš€
842
  colorFrom: blue
 
853
 
854
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
855
  """
856
+ readme_path.write_text(readme_content, encoding="utf-8")
857
+ yield "โœ… README.md created with required configuration"
858
 
859
  # requirements.txt ํ™•์ธ ๋ฐ ๋ฌธ์ œ ํ•ด๊ฒฐ
860
  req_path = Path(folder) / "requirements.txt"
 
1091
  yaml_header = parts[1]
1092
  content = parts[2]
1093
 
1094
+ # repo_id๊ฐ€ ์ •์˜๋˜์ง€ ์•Š์•˜์œผ๋ฏ€๋กœ repo_hf์™€ username ์‚ฌ์šฉ
1095
+ repo_id = f"{username}/{slugify(repo_hf)}"
1096
+
1097
  local_guide = f"""
1098
  ## โš ๏ธ GPU/CUDA Requirements
1099
 
 
1132
  yield "๐Ÿ“ Added GPU setup guide to README.md"
1133
  except Exception as e:
1134
  yield f"โš ๏ธ Could not update README with GPU guide: {str(e)}"
1135
+ except Exception as e:
1136
+ yield f"โš ๏ธ Error processing requirements.txt: {str(e)}"
1137
+
1138
  # Remove .git directory to save space and avoid issues
1139
  git_dir = os.path.join(folder, '.git')
1140
  if os.path.exists(git_dir):
 
1185
  except Exception as e:
1186
  yield f"โš ๏ธ Could not update README.md: {str(e)}"
1187
 
 
 
 
 
 
 
1188
  # Create the HuggingFace repo with retries
1189
  yield "๐Ÿ—๏ธ Creating Hugging Face Space..."
1190
 
 
1240
  if not space_created:
1241
  raise Exception("Failed to create space")
1242
 
 
 
 
 
 
 
1243
  # Check folder size
1244
  folder_size = sum(os.path.getsize(os.path.join(dirpath, filename))
1245
  for dirpath, dirnames, filenames in os.walk(folder)
 
1341
 
1342
  if not upload_success:
1343
  raise Exception("Upload failed after all retries")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1344
 
1345
  # Clean up the temporary folder
1346
  shutil.rmtree(folder)
 
1379
  yield "\n๐Ÿค– **Smart Generation**: An AI-generated Gradio interface was created based on repository analysis"
1380
 
1381
  # ์ถ”๊ฐ€ ์•ˆ๋‚ด์‚ฌํ•ญ
1382
+ if any(dep.startswith("git+") for dep in analysis.get("dependencies", [])) if enable_smart_generation else False:
1383
  yield "\nโš ๏ธ **Build Notice**: This repository contains git dependencies that may take longer to build"
1384
 
1385
  except subprocess.CalledProcessError as e: