Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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 |
-
|
| 834 |
-
|
| 835 |
-
|
| 836 |
-
|
| 837 |
-
|
|
|
|
| 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 |
-
|
| 855 |
-
|
| 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:
|