Spaces:
Build error
Build error
narugo1992
commited on
Commit
·
607013b
1
Parent(s):
462a91c
dev(narugo): add civitai
Browse filesdev(narugo): add caption for skins
- app.py +17 -2
- civitai.py +26 -0
app.py
CHANGED
|
@@ -9,8 +9,11 @@ from gchar.games.dispatch.access import get_character
|
|
| 9 |
from gchar.resources.pixiv import get_pixiv_keywords, get_pixiv_posts
|
| 10 |
from gchar.resources.sites import list_available_sites, get_site_tag
|
| 11 |
from huggingface_hub import hf_hub_url
|
|
|
|
|
|
|
| 12 |
|
| 13 |
from character import get_ch_name
|
|
|
|
| 14 |
from huggingface import get_hf_fs
|
| 15 |
|
| 16 |
hf_fs = get_hf_fs()
|
|
@@ -47,11 +50,13 @@ def query(chr_name):
|
|
| 47 |
if hf_fs.exists(meta_json):
|
| 48 |
meta = json.loads(hf_fs.read_text(meta_json))
|
| 49 |
for item in meta['files']:
|
| 50 |
-
|
| 51 |
'deepghs/game_character_skins',
|
| 52 |
filename=f'{ch.__game_name__}/{ch.index}/{item["name"]}',
|
| 53 |
repo_type='dataset',
|
| 54 |
-
)
|
|
|
|
|
|
|
| 55 |
|
| 56 |
# get repo info
|
| 57 |
repo = f'CyberHarem/{get_ch_name(ch)}'
|
|
@@ -69,6 +74,16 @@ def query(chr_name):
|
|
| 69 |
else:
|
| 70 |
print('Dataset not found.', file=sf)
|
| 71 |
print(file=sf)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 72 |
html = markdown.markdown(sf.getvalue())
|
| 73 |
|
| 74 |
# get tags on all sites
|
|
|
|
| 9 |
from gchar.resources.pixiv import get_pixiv_keywords, get_pixiv_posts
|
| 10 |
from gchar.resources.sites import list_available_sites, get_site_tag
|
| 11 |
from huggingface_hub import hf_hub_url
|
| 12 |
+
from pycivitai import civitai_find_online
|
| 13 |
+
from pycivitai.client import ModelNotFound
|
| 14 |
|
| 15 |
from character import get_ch_name
|
| 16 |
+
from civitai import try_find_title
|
| 17 |
from huggingface import get_hf_fs
|
| 18 |
|
| 19 |
hf_fs = get_hf_fs()
|
|
|
|
| 50 |
if hf_fs.exists(meta_json):
|
| 51 |
meta = json.loads(hf_fs.read_text(meta_json))
|
| 52 |
for item in meta['files']:
|
| 53 |
+
skin_url = hf_hub_url(
|
| 54 |
'deepghs/game_character_skins',
|
| 55 |
filename=f'{ch.__game_name__}/{ch.index}/{item["name"]}',
|
| 56 |
repo_type='dataset',
|
| 57 |
+
)
|
| 58 |
+
skin_name = item['metadata']['name']
|
| 59 |
+
skin_urls.append((skin_url, skin_name))
|
| 60 |
|
| 61 |
# get repo info
|
| 62 |
repo = f'CyberHarem/{get_ch_name(ch)}'
|
|
|
|
| 74 |
else:
|
| 75 |
print('Dataset not found.', file=sf)
|
| 76 |
print(file=sf)
|
| 77 |
+
|
| 78 |
+
try:
|
| 79 |
+
model_name = try_find_title(str(ch.enname), ch.__game_name__)
|
| 80 |
+
resource = civitai_find_online(model_name)
|
| 81 |
+
civit_url = f'https://civitai.com/models/{resource.model_id}'
|
| 82 |
+
print(f'CivitAI Model: [{civit_url}]({civit_url})', file=sf)
|
| 83 |
+
except ModelNotFound:
|
| 84 |
+
print('No CivitAI published model found.', file=sf)
|
| 85 |
+
print(file=sf)
|
| 86 |
+
|
| 87 |
html = markdown.markdown(sf.getvalue())
|
| 88 |
|
| 89 |
# get tags on all sites
|
civitai.py
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from gchar.games.dispatch.access import GAME_CHARS
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
def try_find_title(char_name, game_name):
|
| 5 |
+
try:
|
| 6 |
+
game_cls = GAME_CHARS[game_name.lower()]
|
| 7 |
+
ch = game_cls.get(char_name)
|
| 8 |
+
if ch:
|
| 9 |
+
names = []
|
| 10 |
+
if ch.enname:
|
| 11 |
+
names.append(str(ch.enname))
|
| 12 |
+
if ch.jpname:
|
| 13 |
+
names.append(str(ch.jpname))
|
| 14 |
+
if ch.cnname:
|
| 15 |
+
names.append(str(ch.cnname))
|
| 16 |
+
if hasattr(ch, 'krname') and ch.krname:
|
| 17 |
+
names.append(str(ch.krname))
|
| 18 |
+
|
| 19 |
+
return f"{'/'.join(names)} ({game_cls.__official_name__})"
|
| 20 |
+
|
| 21 |
+
else:
|
| 22 |
+
cname = ' '.join(list(map(str.capitalize, char_name.split(' '))))
|
| 23 |
+
return f'{cname} ({game_cls.__official_name__})'
|
| 24 |
+
|
| 25 |
+
except KeyError:
|
| 26 |
+
return None
|