Spaces:
Sleeping
Sleeping
[feat] add error tips
Browse files- app.py +13 -2
- skills.db +0 -0
- src/tools.py +7 -4
app.py
CHANGED
@@ -145,15 +145,23 @@ def submit_page():
|
|
145 |
suggestions=[],
|
146 |
maxtags = 10,
|
147 |
key='1')
|
148 |
-
|
149 |
if st.form_submit_button('Submit'):
|
|
|
150 |
skills = []
|
|
|
|
|
|
|
|
|
151 |
if skill_names is not None and len(skill_names) > 0:
|
152 |
for skill_name in skill_names:
|
153 |
skill = hf_pull_skill(skill_repository, skill_name)
|
|
|
|
|
|
|
|
|
154 |
skill["repo_id"] = skill_repository
|
155 |
skills.append(skill)
|
156 |
-
|
157 |
if skills is not None and len(skills) > 0:
|
158 |
for skill in skills:
|
159 |
if skill is not None:
|
@@ -162,8 +170,11 @@ def submit_page():
|
|
162 |
result = skill_db.add_skill(skill_obj)
|
163 |
if result != "ok":
|
164 |
st.error(result)
|
|
|
165 |
continue
|
166 |
all_skills.append(skill_obj)
|
|
|
|
|
167 |
|
168 |
chosen_id = stx.tab_bar(data=[
|
169 |
stx.TabBarItemData(id=1, title="π
Skill Library", description=""),
|
|
|
145 |
suggestions=[],
|
146 |
maxtags = 10,
|
147 |
key='1')
|
148 |
+
|
149 |
if st.form_submit_button('Submit'):
|
150 |
+
error = False
|
151 |
skills = []
|
152 |
+
if skill_names is None or len(skill_names)<1:
|
153 |
+
st.error("Please enter at least one skill name! And remeber to press 'Enter' after each skill name.")
|
154 |
+
error = True
|
155 |
+
return
|
156 |
if skill_names is not None and len(skill_names) > 0:
|
157 |
for skill_name in skill_names:
|
158 |
skill = hf_pull_skill(skill_repository, skill_name)
|
159 |
+
if isinstance(skill, Exception):
|
160 |
+
st.error(skill)
|
161 |
+
error = True
|
162 |
+
return
|
163 |
skill["repo_id"] = skill_repository
|
164 |
skills.append(skill)
|
|
|
165 |
if skills is not None and len(skills) > 0:
|
166 |
for skill in skills:
|
167 |
if skill is not None:
|
|
|
170 |
result = skill_db.add_skill(skill_obj)
|
171 |
if result != "ok":
|
172 |
st.error(result)
|
173 |
+
error = True
|
174 |
continue
|
175 |
all_skills.append(skill_obj)
|
176 |
+
if not error:
|
177 |
+
st.success("Skill(s) submitted successfully!")
|
178 |
|
179 |
chosen_id = stx.tab_bar(data=[
|
180 |
stx.TabBarItemData(id=1, title="π
Skill Library", description=""),
|
skills.db
ADDED
Binary file (16.4 kB). View file
|
|
src/tools.py
CHANGED
@@ -3,10 +3,13 @@ from huggingface_hub import hf_hub_download
|
|
3 |
from datetime import datetime
|
4 |
|
5 |
def hf_pull_skill(repo_id, huggingface_skill_path):
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
|
|
|
|
|
|
10 |
|
11 |
def time_ago(updated_at_str):
|
12 |
now = datetime.now()
|
|
|
3 |
from datetime import datetime
|
4 |
|
5 |
def hf_pull_skill(repo_id, huggingface_skill_path):
|
6 |
+
try:
|
7 |
+
return_path = hf_hub_download(repo_id=repo_id, subfolder=huggingface_skill_path, repo_type="space", filename="skill.json")
|
8 |
+
with open(return_path) as f:
|
9 |
+
skill_json = json.load(f)
|
10 |
+
return skill_json
|
11 |
+
except Exception as e:
|
12 |
+
return e
|
13 |
|
14 |
def time_ago(updated_at_str):
|
15 |
now = datetime.now()
|