Upload 2 files
Browse files- dc.py +2 -6
- llmdolphin.py +10 -13
dc.py
CHANGED
@@ -538,10 +538,6 @@ class GuiSD:
|
|
538 |
if save_generated_images:
|
539 |
info_images += f"<br>{download_links}"
|
540 |
|
541 |
-
## BEGIN MOD
|
542 |
-
img = save_images(img, metadata)
|
543 |
-
## END MOD
|
544 |
-
|
545 |
info_state = "COMPLETE"
|
546 |
|
547 |
yield info_state, img, info_images
|
@@ -710,7 +706,7 @@ def infer(prompt, negative_prompt, seed, randomize_seed, width, height, guidance
|
|
710 |
|
711 |
progress(0, desc="Loading model...")
|
712 |
for m in sd_gen.load_new_model(model_name, vae, TASK_MODEL_LIST[0]):
|
713 |
-
|
714 |
progress(1, desc="Model loaded.")
|
715 |
progress(0, desc="Starting Inference...")
|
716 |
images = None
|
@@ -726,7 +722,7 @@ def infer(prompt, negative_prompt, seed, randomize_seed, width, height, guidance
|
|
726 |
True, None, None, "plus_face", "original", 0.7, None, None, "base", "style", 0.7, 0.0,
|
727 |
load_lora_cpu, verbose_info, gpu_duration
|
728 |
):
|
729 |
-
|
730 |
images = stream_images
|
731 |
progress(1, desc="Inference completed.")
|
732 |
output_image = images[0][0] if images else None
|
|
|
538 |
if save_generated_images:
|
539 |
info_images += f"<br>{download_links}"
|
540 |
|
|
|
|
|
|
|
|
|
541 |
info_state = "COMPLETE"
|
542 |
|
543 |
yield info_state, img, info_images
|
|
|
706 |
|
707 |
progress(0, desc="Loading model...")
|
708 |
for m in sd_gen.load_new_model(model_name, vae, TASK_MODEL_LIST[0]):
|
709 |
+
print(m)
|
710 |
progress(1, desc="Model loaded.")
|
711 |
progress(0, desc="Starting Inference...")
|
712 |
images = None
|
|
|
722 |
True, None, None, "plus_face", "original", 0.7, None, None, "base", "style", 0.7, 0.0,
|
723 |
load_lora_cpu, verbose_info, gpu_duration
|
724 |
):
|
725 |
+
print(info_state)
|
726 |
images = stream_images
|
727 |
progress(1, desc="Inference completed.")
|
728 |
output_image = images[0][0] if images else None
|
llmdolphin.py
CHANGED
@@ -1,5 +1,9 @@
|
|
1 |
import spaces
|
2 |
import gradio as gr
|
|
|
|
|
|
|
|
|
3 |
from llama_cpp import Llama
|
4 |
from llama_cpp_agent import LlamaCppAgent, MessagesFormatterType
|
5 |
from llama_cpp_agent.providers import LlamaCppPythonProvider
|
@@ -7,7 +11,6 @@ from llama_cpp_agent.chat_history import BasicChatHistory
|
|
7 |
from llama_cpp_agent.chat_history.messages import Roles
|
8 |
from ja_to_danbooru.ja_to_danbooru import jatags_to_danbooru_tags
|
9 |
import wrapt_timeout_decorator
|
10 |
-
from pathlib import Path
|
11 |
from llama_cpp_agent.messages_formatter import MessagesFormatter
|
12 |
from formatter import mistral_v1_formatter, mistral_v2_formatter, mistral_v3_tekken_formatter
|
13 |
|
@@ -846,6 +849,7 @@ llm_languages = ["English", "Japanese", "Chinese", "Korean", "Spanish", "Portugu
|
|
846 |
llm_models_tupled_list = []
|
847 |
default_llm_model_filename = list(llm_models.keys())[0]
|
848 |
override_llm_format = None
|
|
|
849 |
|
850 |
|
851 |
def to_list(s):
|
@@ -858,7 +862,6 @@ def list_uniq(l):
|
|
858 |
|
859 |
@wrapt_timeout_decorator.timeout(dec_timeout=3.5)
|
860 |
def to_list_ja(s):
|
861 |
-
import re
|
862 |
s = re.sub(r'[、。]', ',', s)
|
863 |
return [x.strip() for x in s.split(",") if not s == ""]
|
864 |
|
@@ -873,7 +876,6 @@ def is_japanese(s):
|
|
873 |
|
874 |
|
875 |
def update_llm_model_tupled_list():
|
876 |
-
from pathlib import Path
|
877 |
global llm_models_tupled_list
|
878 |
llm_models_tupled_list = []
|
879 |
for k, v in llm_models.items():
|
@@ -890,7 +892,6 @@ def update_llm_model_tupled_list():
|
|
890 |
|
891 |
|
892 |
def download_llm_models():
|
893 |
-
from huggingface_hub import hf_hub_download
|
894 |
global llm_models_tupled_list
|
895 |
llm_models_tupled_list = []
|
896 |
for k, v in llm_models.items():
|
@@ -904,7 +905,6 @@ def download_llm_models():
|
|
904 |
|
905 |
|
906 |
def download_llm_model(filename):
|
907 |
-
from huggingface_hub import hf_hub_download
|
908 |
if not filename in llm_models.keys(): return default_llm_model_filename
|
909 |
try:
|
910 |
hf_hub_download(repo_id = llm_models[filename][0], filename = filename, local_dir = llm_models_dir)
|
@@ -965,8 +965,6 @@ def get_dolphin_model_format(filename):
|
|
965 |
|
966 |
|
967 |
def add_dolphin_models(query, format_name):
|
968 |
-
import re
|
969 |
-
from huggingface_hub import HfApi
|
970 |
global llm_models
|
971 |
api = HfApi()
|
972 |
add_models = {}
|
@@ -991,7 +989,6 @@ def add_dolphin_models(query, format_name):
|
|
991 |
except Exception as e:
|
992 |
print(e)
|
993 |
return gr.update(visible=True)
|
994 |
-
#print(add_models)
|
995 |
llm_models = (llm_models | add_models).copy()
|
996 |
update_llm_model_tupled_list()
|
997 |
choices = get_dolphin_models()
|
@@ -1191,7 +1188,6 @@ Output should be enclosed in //GENBEGIN//:// and //://GENEND//. The text to be g
|
|
1191 |
|
1192 |
|
1193 |
def get_dolphin_sysprompt():
|
1194 |
-
import re
|
1195 |
prompt = re.sub('<LANGUAGE>', dolphin_output_language, dolphin_system_prompt.get(dolphin_sysprompt_mode, ""))
|
1196 |
return prompt
|
1197 |
|
@@ -1221,11 +1217,11 @@ def select_dolphin_language(lang: str):
|
|
1221 |
|
1222 |
@wrapt_timeout_decorator.timeout(dec_timeout=5.0)
|
1223 |
def get_raw_prompt(msg: str):
|
1224 |
-
import re
|
1225 |
m = re.findall(r'/GENBEGIN/(.+?)/GENEND/', msg, re.DOTALL)
|
1226 |
return re.sub(r'[*/:_"#\n]', ' ', ", ".join(m)).lower() if m else ""
|
1227 |
|
1228 |
|
|
|
1229 |
@spaces.GPU(duration=60)
|
1230 |
def dolphin_respond(
|
1231 |
message: str,
|
@@ -1239,7 +1235,6 @@ def dolphin_respond(
|
|
1239 |
repeat_penalty: float = 1.1,
|
1240 |
progress=gr.Progress(track_tqdm=True),
|
1241 |
):
|
1242 |
-
from pathlib import Path
|
1243 |
progress(0, desc="Processing...")
|
1244 |
|
1245 |
if override_llm_format:
|
@@ -1320,6 +1315,7 @@ def dolphin_parse(
|
|
1320 |
return ", ".join(prompts), gr.update(interactive=True), gr.update(interactive=True)
|
1321 |
|
1322 |
|
|
|
1323 |
@spaces.GPU(duration=60)
|
1324 |
def dolphin_respond_auto(
|
1325 |
message: str,
|
@@ -1334,7 +1330,6 @@ def dolphin_respond_auto(
|
|
1334 |
progress=gr.Progress(track_tqdm=True),
|
1335 |
):
|
1336 |
#if not is_japanese(message): return [(None, None)]
|
1337 |
-
from pathlib import Path
|
1338 |
progress(0, desc="Processing...")
|
1339 |
|
1340 |
if override_llm_format:
|
@@ -1391,7 +1386,7 @@ def dolphin_respond_auto(
|
|
1391 |
)
|
1392 |
|
1393 |
progress(0.5, desc="Processing...")
|
1394 |
-
|
1395 |
outputs = ""
|
1396 |
for output in stream:
|
1397 |
outputs += output
|
@@ -1421,6 +1416,8 @@ def dolphin_parse_simple(
|
|
1421 |
import cv2
|
1422 |
cv2.setNumThreads(1)
|
1423 |
|
|
|
|
|
1424 |
@spaces.GPU()
|
1425 |
def respond_playground(
|
1426 |
message,
|
|
|
1 |
import spaces
|
2 |
import gradio as gr
|
3 |
+
from pathlib import Path
|
4 |
+
import re
|
5 |
+
import torch
|
6 |
+
from huggingface_hub import hf_hub_download, HfApi
|
7 |
from llama_cpp import Llama
|
8 |
from llama_cpp_agent import LlamaCppAgent, MessagesFormatterType
|
9 |
from llama_cpp_agent.providers import LlamaCppPythonProvider
|
|
|
11 |
from llama_cpp_agent.chat_history.messages import Roles
|
12 |
from ja_to_danbooru.ja_to_danbooru import jatags_to_danbooru_tags
|
13 |
import wrapt_timeout_decorator
|
|
|
14 |
from llama_cpp_agent.messages_formatter import MessagesFormatter
|
15 |
from formatter import mistral_v1_formatter, mistral_v2_formatter, mistral_v3_tekken_formatter
|
16 |
|
|
|
849 |
llm_models_tupled_list = []
|
850 |
default_llm_model_filename = list(llm_models.keys())[0]
|
851 |
override_llm_format = None
|
852 |
+
device = "cuda" if torch.cuda.is_available() else "cpu"
|
853 |
|
854 |
|
855 |
def to_list(s):
|
|
|
862 |
|
863 |
@wrapt_timeout_decorator.timeout(dec_timeout=3.5)
|
864 |
def to_list_ja(s):
|
|
|
865 |
s = re.sub(r'[、。]', ',', s)
|
866 |
return [x.strip() for x in s.split(",") if not s == ""]
|
867 |
|
|
|
876 |
|
877 |
|
878 |
def update_llm_model_tupled_list():
|
|
|
879 |
global llm_models_tupled_list
|
880 |
llm_models_tupled_list = []
|
881 |
for k, v in llm_models.items():
|
|
|
892 |
|
893 |
|
894 |
def download_llm_models():
|
|
|
895 |
global llm_models_tupled_list
|
896 |
llm_models_tupled_list = []
|
897 |
for k, v in llm_models.items():
|
|
|
905 |
|
906 |
|
907 |
def download_llm_model(filename):
|
|
|
908 |
if not filename in llm_models.keys(): return default_llm_model_filename
|
909 |
try:
|
910 |
hf_hub_download(repo_id = llm_models[filename][0], filename = filename, local_dir = llm_models_dir)
|
|
|
965 |
|
966 |
|
967 |
def add_dolphin_models(query, format_name):
|
|
|
|
|
968 |
global llm_models
|
969 |
api = HfApi()
|
970 |
add_models = {}
|
|
|
989 |
except Exception as e:
|
990 |
print(e)
|
991 |
return gr.update(visible=True)
|
|
|
992 |
llm_models = (llm_models | add_models).copy()
|
993 |
update_llm_model_tupled_list()
|
994 |
choices = get_dolphin_models()
|
|
|
1188 |
|
1189 |
|
1190 |
def get_dolphin_sysprompt():
|
|
|
1191 |
prompt = re.sub('<LANGUAGE>', dolphin_output_language, dolphin_system_prompt.get(dolphin_sysprompt_mode, ""))
|
1192 |
return prompt
|
1193 |
|
|
|
1217 |
|
1218 |
@wrapt_timeout_decorator.timeout(dec_timeout=5.0)
|
1219 |
def get_raw_prompt(msg: str):
|
|
|
1220 |
m = re.findall(r'/GENBEGIN/(.+?)/GENEND/', msg, re.DOTALL)
|
1221 |
return re.sub(r'[*/:_"#\n]', ' ', ", ".join(m)).lower() if m else ""
|
1222 |
|
1223 |
|
1224 |
+
@torch.inference_mode()
|
1225 |
@spaces.GPU(duration=60)
|
1226 |
def dolphin_respond(
|
1227 |
message: str,
|
|
|
1235 |
repeat_penalty: float = 1.1,
|
1236 |
progress=gr.Progress(track_tqdm=True),
|
1237 |
):
|
|
|
1238 |
progress(0, desc="Processing...")
|
1239 |
|
1240 |
if override_llm_format:
|
|
|
1315 |
return ", ".join(prompts), gr.update(interactive=True), gr.update(interactive=True)
|
1316 |
|
1317 |
|
1318 |
+
@torch.inference_mode()
|
1319 |
@spaces.GPU(duration=60)
|
1320 |
def dolphin_respond_auto(
|
1321 |
message: str,
|
|
|
1330 |
progress=gr.Progress(track_tqdm=True),
|
1331 |
):
|
1332 |
#if not is_japanese(message): return [(None, None)]
|
|
|
1333 |
progress(0, desc="Processing...")
|
1334 |
|
1335 |
if override_llm_format:
|
|
|
1386 |
)
|
1387 |
|
1388 |
progress(0.5, desc="Processing...")
|
1389 |
+
|
1390 |
outputs = ""
|
1391 |
for output in stream:
|
1392 |
outputs += output
|
|
|
1416 |
import cv2
|
1417 |
cv2.setNumThreads(1)
|
1418 |
|
1419 |
+
|
1420 |
+
@torch.inference_mode()
|
1421 |
@spaces.GPU()
|
1422 |
def respond_playground(
|
1423 |
message,
|