Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -14,40 +14,11 @@
|
|
| 14 |
# See the License for the specific language governing permissions and
|
| 15 |
# limitations under the License.
|
| 16 |
|
| 17 |
-
import argparse
|
| 18 |
-
import os.path
|
| 19 |
-
|
| 20 |
import torch
|
| 21 |
from diffusers import AutoPipelineForText2Image, LCMScheduler
|
| 22 |
from llama_cpp import Llama
|
| 23 |
import gradio as gr
|
| 24 |
|
| 25 |
-
parser = argparse.ArgumentParser(description='Japanese translation and hallucinations for SD')
|
| 26 |
-
parser.add_argument('--gguf_path',
|
| 27 |
-
type=str,
|
| 28 |
-
default=None,
|
| 29 |
-
help='load gguf filepath')
|
| 30 |
-
parser.add_argument('--sd_model_name',
|
| 31 |
-
type=str,
|
| 32 |
-
default="segmind/SSD-1B",
|
| 33 |
-
help='sd model HF name')
|
| 34 |
-
parser.add_argument('--sd_adapter_name',
|
| 35 |
-
type=str,
|
| 36 |
-
default="latent-consistency/lcm-lora-ssd-1b",
|
| 37 |
-
help='sd lora adaptor HF name')
|
| 38 |
-
parser.add_argument('--cpu',
|
| 39 |
-
action='store_true',
|
| 40 |
-
help='force use cpu (intel).')
|
| 41 |
-
parser.add_argument('--share',
|
| 42 |
-
action='store_true',
|
| 43 |
-
help='force use cpu.')
|
| 44 |
-
parser.add_argument('--openvino_path',
|
| 45 |
-
type=str,
|
| 46 |
-
default=None,
|
| 47 |
-
help='load openvio model filepath')
|
| 48 |
-
|
| 49 |
-
args = parser.parse_args()
|
| 50 |
-
|
| 51 |
llm_model_path = args.gguf_path
|
| 52 |
sd_model_name = args.sd_model_name
|
| 53 |
sd_adapter_name = args.sd_adapter_name
|
|
@@ -59,50 +30,15 @@ height = 512
|
|
| 59 |
num_inference_steps = 4
|
| 60 |
guidance_scale = 1.0
|
| 61 |
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
download_folder = snapshot_download(repo_id="Intel/sd-1.5-lcm-openvino")
|
| 67 |
-
import shutil
|
| 68 |
-
shutil.copytree(download_folder, "./sd-1.5-lcm-openvino'")
|
| 69 |
-
args.openvino_path = './sd-1.5-lcm-openvino'
|
| 70 |
-
else:
|
| 71 |
-
args.openvino_path = './sd-1.5-lcm-openvino'
|
| 72 |
-
from openvino_pipe import LatentConsistencyEngine
|
| 73 |
-
pipe = LatentConsistencyEngine(
|
| 74 |
-
args.openvino_path
|
| 75 |
-
)
|
| 76 |
-
else:
|
| 77 |
-
pipe = AutoPipelineForText2Image.from_pretrained(
|
| 78 |
-
sd_model_name,
|
| 79 |
-
torch_dtype=torch.float16 if use_cuda else torch.float32,
|
| 80 |
-
)
|
| 81 |
-
pipe.scheduler = LCMScheduler.from_config(pipe.scheduler.config)
|
| 82 |
-
|
| 83 |
-
if use_cuda:
|
| 84 |
-
pipe.enable_xformers_memory_efficient_attention()
|
| 85 |
-
pipe.enable_model_cpu_offload()
|
| 86 |
-
pipe.to("cuda")
|
| 87 |
-
|
| 88 |
-
if sd_adapter_name is not None:
|
| 89 |
-
pipe.load_lora_weights(sd_adapter_name)
|
| 90 |
-
if use_cuda:
|
| 91 |
-
pipe.fuse_lora()
|
| 92 |
-
|
| 93 |
-
if llm_model_path is None:
|
| 94 |
-
from huggingface_hub import hf_hub_download
|
| 95 |
-
llm_model_path = hf_hub_download(
|
| 96 |
-
repo_id="taoki/llm-jp-1.3b-v1.0-staircaptions-FT",
|
| 97 |
-
filename="llm-jp-1.3b-v1.0_staircaptions-FT_Q4_K_S.gguf",
|
| 98 |
-
)
|
| 99 |
|
| 100 |
llm = Llama(
|
| 101 |
-
model_path=
|
| 102 |
-
n_gpu_layers=25 if use_cuda else -1,
|
| 103 |
)
|
| 104 |
|
| 105 |
-
|
| 106 |
def ja2prompt(ja_prompt):
|
| 107 |
response = llm(f"### Instruction:\n{ja_prompt}\n### Response:\n", max_tokens=128)
|
| 108 |
return response['choices'][0]['text']
|
|
|
|
| 14 |
# See the License for the specific language governing permissions and
|
| 15 |
# limitations under the License.
|
| 16 |
|
|
|
|
|
|
|
|
|
|
| 17 |
import torch
|
| 18 |
from diffusers import AutoPipelineForText2Image, LCMScheduler
|
| 19 |
from llama_cpp import Llama
|
| 20 |
import gradio as gr
|
| 21 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
llm_model_path = args.gguf_path
|
| 23 |
sd_model_name = args.sd_model_name
|
| 24 |
sd_adapter_name = args.sd_adapter_name
|
|
|
|
| 30 |
num_inference_steps = 4
|
| 31 |
guidance_scale = 1.0
|
| 32 |
|
| 33 |
+
from openvino_pipe import LatentConsistencyEngine
|
| 34 |
+
pipe = LatentConsistencyEngine(
|
| 35 |
+
"Intel/sd-1.5-lcm-openvino"
|
| 36 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
|
| 38 |
llm = Llama(
|
| 39 |
+
model_path="llm-jp-1.3b-v1.0_staircaptions-FT_Q4_K_S.gguf",
|
|
|
|
| 40 |
)
|
| 41 |
|
|
|
|
| 42 |
def ja2prompt(ja_prompt):
|
| 43 |
response = llm(f"### Instruction:\n{ja_prompt}\n### Response:\n", max_tokens=128)
|
| 44 |
return response['choices'][0]['text']
|