Update app.py
Browse files
    	
        app.py
    CHANGED
    
    | @@ -1,5 +1,572 @@ | |
| 1 | 
             
            import sys
         | 
|  | |
| 2 |  | 
| 3 | 
            -
             | 
| 4 |  | 
| 5 | 
            -
             | 
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | 
|  | |
| 1 | 
             
            import sys
         | 
| 2 | 
            +
            import os
         | 
| 3 |  | 
| 4 | 
            +
            argv = os.environ.get('VALLE_ARGS', None)
         | 
| 5 |  | 
| 6 | 
            +
            if argv:
         | 
| 7 | 
            +
            	sys.argv = sys.argv + argv.split(" ")
         | 
| 8 | 
            +
             | 
| 9 | 
            +
            import re
         | 
| 10 | 
            +
            import math
         | 
| 11 | 
            +
            import argparse
         | 
| 12 | 
            +
            import random
         | 
| 13 | 
            +
            import tempfile
         | 
| 14 | 
            +
            import functools
         | 
| 15 | 
            +
            import spaces
         | 
| 16 | 
            +
             | 
| 17 | 
            +
            import torch
         | 
| 18 | 
            +
            import numpy as np
         | 
| 19 | 
            +
             | 
| 20 | 
            +
            import torchaudio
         | 
| 21 | 
            +
            import gradio as gr
         | 
| 22 | 
            +
             | 
| 23 | 
            +
            from pathlib import Path
         | 
| 24 | 
            +
             | 
| 25 | 
            +
            from vall_e.inference import TTS, cfg
         | 
| 26 | 
            +
            from vall_e.train import train
         | 
| 27 | 
            +
            from vall_e.utils import get_devices, setup_logging, timer
         | 
| 28 | 
            +
            from vall_e.utils.io import json_read, json_stringify
         | 
| 29 | 
            +
            from vall_e.emb.qnt import decode_to_wave
         | 
| 30 | 
            +
            from vall_e.data import get_lang_symmap, get_random_prompt
         | 
| 31 | 
            +
            from vall_e.models.arch import AVAILABLE_ATTENTIONS
         | 
| 32 | 
            +
             | 
| 33 | 
            +
            try:
         | 
| 34 | 
            +
            	import spaces
         | 
| 35 | 
            +
             | 
| 36 | 
            +
            	USING_SPACES = True
         | 
| 37 | 
            +
            	spaces_zerogpu_decorator = spaces.GPU
         | 
| 38 | 
            +
            except Exception as e:
         | 
| 39 | 
            +
            	USING_SPACES = False
         | 
| 40 | 
            +
            	def spaces_zerogpu_decorator(func):
         | 
| 41 | 
            +
            		return func
         | 
| 42 | 
            +
             | 
| 43 | 
            +
            is_windows = sys.platform.startswith("win")
         | 
| 44 | 
            +
             | 
| 45 | 
            +
            tts = None
         | 
| 46 | 
            +
             | 
| 47 | 
            +
            layout = {}
         | 
| 48 | 
            +
            layout["inference_tts"] = {}
         | 
| 49 | 
            +
            layout["inference_stt"] = {}
         | 
| 50 | 
            +
            layout["training"] = {}
         | 
| 51 | 
            +
            layout["dataset"] = {}
         | 
| 52 | 
            +
            layout["settings"] = {}
         | 
| 53 | 
            +
             | 
| 54 | 
            +
            for k in layout.keys():
         | 
| 55 | 
            +
            	layout[k]["inputs"] = { "progress": None }
         | 
| 56 | 
            +
            	layout[k]["outputs"] = {}
         | 
| 57 | 
            +
            	layout[k]["buttons"] = {}
         | 
| 58 | 
            +
             | 
| 59 | 
            +
            # there's got to be a better way to go about this
         | 
| 60 | 
            +
            def gradio_wrapper(inputs):
         | 
| 61 | 
            +
            	def decorated(fun):
         | 
| 62 | 
            +
            		@functools.wraps(fun)
         | 
| 63 | 
            +
            		def wrapped_function(*args, **kwargs):
         | 
| 64 | 
            +
            			for i, key in enumerate(inputs):
         | 
| 65 | 
            +
            				kwargs[key] = args[i]
         | 
| 66 | 
            +
            			try:
         | 
| 67 | 
            +
            				return fun(**kwargs)
         | 
| 68 | 
            +
            			except Exception as e:
         | 
| 69 | 
            +
            				raise gr.Error(str(e))
         | 
| 70 | 
            +
            		return wrapped_function
         | 
| 71 | 
            +
            	return decorated
         | 
| 72 | 
            +
             | 
| 73 | 
            +
            # returns a list of models, assuming the models are placed under ./training/ or ./models/ or ./data/models/
         | 
| 74 | 
            +
            def get_model_paths( paths=[Path("./training/"), Path("./models/"), Path("./data/models/")] ):
         | 
| 75 | 
            +
            	configs = []
         | 
| 76 | 
            +
             | 
| 77 | 
            +
            	for path in paths:
         | 
| 78 | 
            +
            		if not path.exists():
         | 
| 79 | 
            +
            			continue
         | 
| 80 | 
            +
             | 
| 81 | 
            +
            		for yaml in path.glob("**/*.yaml"):
         | 
| 82 | 
            +
            			if "/logs/" in str(yaml):
         | 
| 83 | 
            +
            				continue
         | 
| 84 | 
            +
            			configs.append( yaml )
         | 
| 85 | 
            +
            		
         | 
| 86 | 
            +
            		for sft in path.glob("**/*.sft"):
         | 
| 87 | 
            +
            			if "/logs/" in str(sft):
         | 
| 88 | 
            +
            				continue
         | 
| 89 | 
            +
            			configs.append( sft )
         | 
| 90 | 
            +
             | 
| 91 | 
            +
            	if is_windows:
         | 
| 92 | 
            +
            		configs = [ str(p) for p in configs ]
         | 
| 93 | 
            +
             | 
| 94 | 
            +
            	return configs
         | 
| 95 | 
            +
             | 
| 96 | 
            +
            def get_dtypes():
         | 
| 97 | 
            +
            	return ["float32", "float16", "bfloat16", "float8_e5m2", "float8_e4m3fn", "auto"]
         | 
| 98 | 
            +
             | 
| 99 | 
            +
            def get_attentions():
         | 
| 100 | 
            +
            	return AVAILABLE_ATTENTIONS + ["auto"]
         | 
| 101 | 
            +
             | 
| 102 | 
            +
            #@gradio_wrapper(inputs=layout["settings"]["inputs"].keys())
         | 
| 103 | 
            +
            def load_model( config, device, dtype, attention ):
         | 
| 104 | 
            +
            	gr.Info(f"Loading: {config}")
         | 
| 105 | 
            +
            	try:
         | 
| 106 | 
            +
            		init_tts( config=Path(config), restart=True, device=device, dtype=dtype, attention=attention )
         | 
| 107 | 
            +
            	except Exception as e:
         | 
| 108 | 
            +
            		raise gr.Error(e)
         | 
| 109 | 
            +
            	gr.Info(f"Loaded model")
         | 
| 110 | 
            +
             | 
| 111 | 
            +
            def get_speakers():
         | 
| 112 | 
            +
            	return cfg.dataset.training
         | 
| 113 | 
            +
             | 
| 114 | 
            +
            def get_languages():
         | 
| 115 | 
            +
            	return get_lang_symmap().keys()
         | 
| 116 | 
            +
             | 
| 117 | 
            +
            #@gradio_wrapper(inputs=layout["dataset"]["inputs"].keys())
         | 
| 118 | 
            +
            def load_sample( speaker ):
         | 
| 119 | 
            +
            	metadata_path = cfg.metadata_dir / f'{speaker}.json'
         | 
| 120 | 
            +
            	metadata = json_read( metadata_path )
         | 
| 121 | 
            +
            	if not metadata:
         | 
| 122 | 
            +
            		raise gr.Error(f"Metadata not found: {metadata_path}")
         | 
| 123 | 
            +
             | 
| 124 | 
            +
            	key = random.choice( list(metadata.keys()) )
         | 
| 125 | 
            +
            	path = cfg.data_dir / speaker / f'{key}.enc' # to-do: get proper file extension
         | 
| 126 | 
            +
            	data = json_stringify( metadata[key], pretty=True )
         | 
| 127 | 
            +
            	wav, sr = None, None
         | 
| 128 | 
            +
             | 
| 129 | 
            +
            	if path.exists():
         | 
| 130 | 
            +
            		artifact = np.load(path, allow_pickle=True)[()]
         | 
| 131 | 
            +
            		codes = torch.from_numpy(artifact["codes"].astype(int))[0].t().to(dtype=torch.int16, device=cfg.device)
         | 
| 132 | 
            +
            		wav, sr = decode_to_wave( codes )
         | 
| 133 | 
            +
            		wav = wav.squeeze(0).cpu().numpy()
         | 
| 134 | 
            +
             | 
| 135 | 
            +
            	return data, (sr, wav)
         | 
| 136 | 
            +
             | 
| 137 | 
            +
            def init_tts(config=None, lora=None, restart=False, device="cuda", dtype="auto", attention=None):
         | 
| 138 | 
            +
            	global tts
         | 
| 139 | 
            +
             | 
| 140 | 
            +
            	if tts is not None:
         | 
| 141 | 
            +
            		if not restart:
         | 
| 142 | 
            +
            			return tts
         | 
| 143 | 
            +
            		
         | 
| 144 | 
            +
            		del tts
         | 
| 145 | 
            +
            		tts = None
         | 
| 146 | 
            +
            	
         | 
| 147 | 
            +
            	parser = argparse.ArgumentParser(allow_abbrev=False, add_help=False)
         | 
| 148 | 
            +
            	parser.add_argument("--yaml", type=Path, default=os.environ.get('VALLE_YAML', None)) # os environ so it can be specified in a HuggingFace Space too
         | 
| 149 | 
            +
            	parser.add_argument("--model", type=Path, default=os.environ.get('VALLE_MODEL', None)) # os environ so it can be specified in a HuggingFace Space too
         | 
| 150 | 
            +
            	parser.add_argument("--lora", type=Path, default=os.environ.get('VALLE_LORA', None)) # os environ so it can be specified in a HuggingFace Space too
         | 
| 151 | 
            +
            	parser.add_argument("--device", type=str, default=device)
         | 
| 152 | 
            +
            	parser.add_argument("--amp", action="store_true")
         | 
| 153 | 
            +
            	parser.add_argument("--dtype", type=str, default=dtype)
         | 
| 154 | 
            +
            	parser.add_argument("--attention", type=str, default=attention)
         | 
| 155 | 
            +
            	args, unknown = parser.parse_known_args()
         | 
| 156 | 
            +
             | 
| 157 | 
            +
            	if config:
         | 
| 158 | 
            +
            		if config.suffix == ".yaml" and not args.yaml:
         | 
| 159 | 
            +
            			args.yaml = config
         | 
| 160 | 
            +
            		elif config.suffix == ".sft" and not args.model:
         | 
| 161 | 
            +
            			args.model = config
         | 
| 162 | 
            +
             | 
| 163 | 
            +
            	if lora and not args.lora:
         | 
| 164 | 
            +
            		args.lora = lora
         | 
| 165 | 
            +
             | 
| 166 | 
            +
            	if args.yaml:
         | 
| 167 | 
            +
            		config = args.yaml
         | 
| 168 | 
            +
            	elif args.model:
         | 
| 169 | 
            +
            		config = args.model
         | 
| 170 | 
            +
             | 
| 171 | 
            +
            	if args.lora:
         | 
| 172 | 
            +
            		lora = args.lora
         | 
| 173 | 
            +
             | 
| 174 | 
            +
            	tts = TTS( config=config, lora=args.lora, device=args.device, dtype=args.dtype if args.dtype != "auto" else None, amp=args.amp, attention=args.attention )
         | 
| 175 | 
            +
            	return tts
         | 
| 176 | 
            +
             | 
| 177 | 
            +
            @spaces_zerogpu_decorator
         | 
| 178 | 
            +
            @gradio_wrapper(inputs=layout["inference_tts"]["inputs"].keys())
         | 
| 179 | 
            +
            def do_inference_tts( progress=gr.Progress(track_tqdm=True), *args, **kwargs ):
         | 
| 180 | 
            +
            	if not cfg.models:
         | 
| 181 | 
            +
            		raise Exception("No model loaded.")
         | 
| 182 | 
            +
             | 
| 183 | 
            +
            	if kwargs.pop("dynamic-sampling", False):
         | 
| 184 | 
            +
            		kwargs['min-ar-temp'] = 0.01 if kwargs['ar-temp'] > 0.01 else 0.0
         | 
| 185 | 
            +
            		kwargs['min-nar-temp'] = 0.0 # 0.85 if kwargs['nar-temp'] > 0.85 else 0.0 # should probably disable it for the NAR
         | 
| 186 | 
            +
            	else:
         | 
| 187 | 
            +
            		kwargs['min-ar-temp'] = -1
         | 
| 188 | 
            +
            		kwargs['min-nar-temp'] = -1
         | 
| 189 | 
            +
             | 
| 190 | 
            +
            	parser = argparse.ArgumentParser(allow_abbrev=False, add_help=False)
         | 
| 191 | 
            +
            	# I'm very sure I can procedurally generate this list
         | 
| 192 | 
            +
            	parser.add_argument("--text", type=str, default=kwargs["text"])
         | 
| 193 | 
            +
            	parser.add_argument("--task", type=str, default="tts")
         | 
| 194 | 
            +
            	parser.add_argument("--references", type=str, default=kwargs["reference"])
         | 
| 195 | 
            +
            	parser.add_argument("--language", type=str, default=kwargs["language"])
         | 
| 196 | 
            +
            	parser.add_argument("--input-prompt-length", type=float, default=kwargs["input-prompt-length"])
         | 
| 197 | 
            +
            	parser.add_argument("--input-prompt-prefix", action='store_true', default=kwargs["input-prompt-prefix"] if cfg.experimental else False)
         | 
| 198 | 
            +
            	parser.add_argument("--max-ar-steps", type=int, default=int(kwargs["max-seconds"]*cfg.dataset.frames_per_second))
         | 
| 199 | 
            +
            	parser.add_argument("--max-nar-levels", type=int, default=kwargs["max-nar-levels"] if cfg.experimental else 0)
         | 
| 200 | 
            +
            	parser.add_argument("--ar-temp", type=float, default=kwargs["ar-temp"])
         | 
| 201 | 
            +
            	parser.add_argument("--nar-temp", type=float, default=kwargs["nar-temp"])
         | 
| 202 | 
            +
            	parser.add_argument("--min-ar-temp", type=float, default=kwargs["min-ar-temp"])
         | 
| 203 | 
            +
            	parser.add_argument("--min-nar-temp", type=float, default=kwargs["min-nar-temp"])
         | 
| 204 | 
            +
            	parser.add_argument("--prefix-silence", type=float, default=kwargs["prefix-silence"] if cfg.experimental else 0)
         | 
| 205 | 
            +
            	parser.add_argument("--top-p", type=float, default=kwargs["top-p"])
         | 
| 206 | 
            +
            	parser.add_argument("--top-k", type=int, default=kwargs["top-k"])
         | 
| 207 | 
            +
            	parser.add_argument("--min-p", type=float, default=kwargs["min-p"])
         | 
| 208 | 
            +
            	parser.add_argument("--repetition-penalty", type=float, default=kwargs["repetition-penalty"])
         | 
| 209 | 
            +
            	parser.add_argument("--repetition-penalty-decay", type=float, default=kwargs["repetition-penalty-decay"])
         | 
| 210 | 
            +
            	parser.add_argument("--length-penalty", type=float, default=kwargs["length-penalty"])
         | 
| 211 | 
            +
            	parser.add_argument("--beam-width", type=int, default=kwargs["beam-width"])
         | 
| 212 | 
            +
            	parser.add_argument("--mirostat-tau", type=float, default=kwargs["mirostat-tau"])
         | 
| 213 | 
            +
            	parser.add_argument("--mirostat-eta", type=float, default=kwargs["mirostat-eta"])
         | 
| 214 | 
            +
            	parser.add_argument("--dry-multiplier", type=float, default=kwargs["dry-multiplier"])
         | 
| 215 | 
            +
            	parser.add_argument("--dry-base", type=float, default=kwargs["dry-base"])
         | 
| 216 | 
            +
            	parser.add_argument("--dry-allowed-length", type=int, default=kwargs["dry-allowed-length"])
         | 
| 217 | 
            +
            	parser.add_argument("--entropix-sampling", action="store_true")
         | 
| 218 | 
            +
            	parser.add_argument("--layer-skip", action="store_true")
         | 
| 219 | 
            +
            	parser.add_argument("--layer-skip-exit-layer", type=int, default=kwargs["layer-skip-exit-layer"] if cfg.experimental else -1)
         | 
| 220 | 
            +
            	parser.add_argument("--layer-skip-entropy-threshold", type=int, default=kwargs["layer-skip-entropy-threshold"] if cfg.experimental else 0.1)
         | 
| 221 | 
            +
            	parser.add_argument("--layer-skip-varentropy-threshold", type=int, default=kwargs["layer-skip-varentropy-threshold"] if cfg.experimental else 0.1)
         | 
| 222 | 
            +
            	parser.add_argument("--refine-on-stop", action="store_true")
         | 
| 223 | 
            +
            	args, unknown = parser.parse_known_args()
         | 
| 224 | 
            +
             | 
| 225 | 
            +
            	if is_windows:
         | 
| 226 | 
            +
            		tmp = tempfile.NamedTemporaryFile(suffix='.wav', delete=False)
         | 
| 227 | 
            +
            	else:
         | 
| 228 | 
            +
            		tmp = tempfile.NamedTemporaryFile(suffix='.wav')
         | 
| 229 | 
            +
             | 
| 230 | 
            +
            	"""
         | 
| 231 | 
            +
            	if not args.references:
         | 
| 232 | 
            +
            		raise Exception("No reference audio provided.")
         | 
| 233 | 
            +
            	"""
         | 
| 234 | 
            +
             | 
| 235 | 
            +
            	if kwargs.pop("entropix-sampling", False):
         | 
| 236 | 
            +
            		args.entropix_sampling = True
         | 
| 237 | 
            +
            	
         | 
| 238 | 
            +
            	if kwargs.pop("layer-skip", False):
         | 
| 239 | 
            +
            		args.layer_skip = True
         | 
| 240 | 
            +
            	
         | 
| 241 | 
            +
            	if kwargs.pop("refine-on-stop", False):
         | 
| 242 | 
            +
            		args.refine_on_stop = True
         | 
| 243 | 
            +
             | 
| 244 | 
            +
            	tts = init_tts()
         | 
| 245 | 
            +
            	
         | 
| 246 | 
            +
            	gr.Info("Inferencing...")
         | 
| 247 | 
            +
            	
         | 
| 248 | 
            +
            	with timer("Inferenced in", callback=lambda msg: gr.Info( msg )) as t:
         | 
| 249 | 
            +
            		wav, sr = tts.inference(
         | 
| 250 | 
            +
            			text=args.text,
         | 
| 251 | 
            +
            			language=args.language,
         | 
| 252 | 
            +
            			task=args.task,
         | 
| 253 | 
            +
            			references=args.references.split(";") if args.references is not None else [],
         | 
| 254 | 
            +
            			out_path=tmp.name,
         | 
| 255 | 
            +
            			max_ar_steps=args.max_ar_steps,
         | 
| 256 | 
            +
            			max_nar_levels=args.max_nar_levels,
         | 
| 257 | 
            +
            			input_prompt_length=args.input_prompt_length,
         | 
| 258 | 
            +
            			input_prompt_prefix=args.input_prompt_prefix,
         | 
| 259 | 
            +
            			prefix_silence=args.prefix_silence,
         | 
| 260 | 
            +
            			ar_temp=args.ar_temp,
         | 
| 261 | 
            +
            			nar_temp=args.nar_temp,
         | 
| 262 | 
            +
            			min_ar_temp=args.min_ar_temp,
         | 
| 263 | 
            +
            			min_nar_temp=args.min_nar_temp,
         | 
| 264 | 
            +
            			top_p=args.top_p,
         | 
| 265 | 
            +
            			top_k=args.top_k,
         | 
| 266 | 
            +
            			min_p=args.min_p,
         | 
| 267 | 
            +
            			beam_width=args.beam_width,
         | 
| 268 | 
            +
            			repetition_penalty=args.repetition_penalty,
         | 
| 269 | 
            +
            			repetition_penalty_decay=args.repetition_penalty_decay,
         | 
| 270 | 
            +
            			length_penalty=args.length_penalty,
         | 
| 271 | 
            +
            			mirostat_tau=args.mirostat_tau,
         | 
| 272 | 
            +
            			mirostat_eta=args.mirostat_eta,
         | 
| 273 | 
            +
            			dry_multiplier=args.dry_multiplier,
         | 
| 274 | 
            +
            			dry_base=args.dry_base,
         | 
| 275 | 
            +
            			dry_allowed_length=args.dry_allowed_length,
         | 
| 276 | 
            +
            			entropix_sampling=args.entropix_sampling,
         | 
| 277 | 
            +
            			
         | 
| 278 | 
            +
            			layer_skip=args.layer_skip,
         | 
| 279 | 
            +
            			layer_skip_entropy_threshold=args.layer_skip_entropy_threshold,
         | 
| 280 | 
            +
            			layer_skip_varentropy_threshold=args.layer_skip_varentropy_threshold,
         | 
| 281 | 
            +
            			refine_on_stop=args.refine_on_stop,
         | 
| 282 | 
            +
            		)
         | 
| 283 | 
            +
            	
         | 
| 284 | 
            +
            	wav = wav.squeeze(0).cpu().numpy()
         | 
| 285 | 
            +
            	return (sr, wav)
         | 
| 286 | 
            +
             | 
| 287 | 
            +
            @gradio_wrapper(inputs=layout["inference_stt"]["inputs"].keys())
         | 
| 288 | 
            +
            def do_inference_stt( progress=gr.Progress(track_tqdm=True), *args, **kwargs ):
         | 
| 289 | 
            +
            	if not cfg.models:
         | 
| 290 | 
            +
            		raise Exception("No model loaded.")
         | 
| 291 | 
            +
             | 
| 292 | 
            +
            	if kwargs.pop("dynamic-sampling", False):
         | 
| 293 | 
            +
            		kwargs['min-ar-temp'] = 0.85 if kwargs['ar-temp'] > 0.85 else 0.0
         | 
| 294 | 
            +
            	else:
         | 
| 295 | 
            +
            		kwargs['min-ar-temp'] = -1
         | 
| 296 | 
            +
             | 
| 297 | 
            +
            	parser = argparse.ArgumentParser(allow_abbrev=False, add_help=False)
         | 
| 298 | 
            +
            	# I'm very sure I can procedurally generate this list
         | 
| 299 | 
            +
            	parser.add_argument("--references", type=str, default=kwargs["reference"])
         | 
| 300 | 
            +
            	parser.add_argument("--language", type=str, default=kwargs["language"])
         | 
| 301 | 
            +
            	parser.add_argument("--max-ar-steps", type=int, default=0)
         | 
| 302 | 
            +
            	parser.add_argument("--ar-temp", type=float, default=kwargs["ar-temp"])
         | 
| 303 | 
            +
            	parser.add_argument("--min-ar-temp", type=float, default=kwargs["min-ar-temp"])
         | 
| 304 | 
            +
            	parser.add_argument("--top-p", type=float, default=kwargs["top-p"])
         | 
| 305 | 
            +
            	parser.add_argument("--top-k", type=int, default=kwargs["top-k"])
         | 
| 306 | 
            +
            	parser.add_argument("--min-p", type=int, default=kwargs["min-p"])
         | 
| 307 | 
            +
            	parser.add_argument("--repetition-penalty", type=float, default=kwargs["repetition-penalty"])
         | 
| 308 | 
            +
            	parser.add_argument("--repetition-penalty-decay", type=float, default=kwargs["repetition-penalty-decay"])
         | 
| 309 | 
            +
            	parser.add_argument("--length-penalty", type=float, default=kwargs["length-penalty"])
         | 
| 310 | 
            +
            	parser.add_argument("--beam-width", type=int, default=kwargs["beam-width"])
         | 
| 311 | 
            +
            	parser.add_argument("--mirostat-tau", type=float, default=kwargs["mirostat-tau"])
         | 
| 312 | 
            +
            	parser.add_argument("--mirostat-eta", type=float, default=kwargs["mirostat-eta"])
         | 
| 313 | 
            +
            	parser.add_argument("--dry-multiplier", type=float, default=kwargs["dry-multiplier"])
         | 
| 314 | 
            +
            	parser.add_argument("--dry-base", type=float, default=kwargs["dry-base"])
         | 
| 315 | 
            +
            	parser.add_argument("--dry-allowed-length", type=int, default=kwargs["dry-allowed-length"])
         | 
| 316 | 
            +
            	parser.add_argument("--entropix-sampling", action="store_true")
         | 
| 317 | 
            +
            	args, unknown = parser.parse_known_args()
         | 
| 318 | 
            +
             | 
| 319 | 
            +
             | 
| 320 | 
            +
            	"""
         | 
| 321 | 
            +
            	if not args.references:
         | 
| 322 | 
            +
            		raise Exception("No reference audio provided.")
         | 
| 323 | 
            +
            	"""
         | 
| 324 | 
            +
             | 
| 325 | 
            +
            	args.references = args.references.split(";") if args.references is not None else []
         | 
| 326 | 
            +
            	if args.max_ar_steps == 0:
         | 
| 327 | 
            +
            		for i, path in enumerate( args.references ):
         | 
| 328 | 
            +
            			metadata = torchaudio.info(path)
         | 
| 329 | 
            +
            			duration = metadata.num_frames / metadata.sample_rate
         | 
| 330 | 
            +
            			args.max_ar_steps += duration
         | 
| 331 | 
            +
            		args.max_ar_steps = math.floor( args.max_ar_steps * 20 ) # assume 20 tokens per second
         | 
| 332 | 
            +
            	
         | 
| 333 | 
            +
            	if kwargs.pop("entropix-sampling", False):
         | 
| 334 | 
            +
            		args.entropix_sampling = True
         | 
| 335 | 
            +
             | 
| 336 | 
            +
            	tts = init_tts()
         | 
| 337 | 
            +
            	
         | 
| 338 | 
            +
            	gr.Info("Inferencing...")
         | 
| 339 | 
            +
            	with timer("Inferenced in") as t:
         | 
| 340 | 
            +
            		text = tts.inference(
         | 
| 341 | 
            +
            			text="",
         | 
| 342 | 
            +
            			language=args.language,
         | 
| 343 | 
            +
            			task="stt",
         | 
| 344 | 
            +
            			references=args.references,
         | 
| 345 | 
            +
            			max_ar_steps=args.max_ar_steps,
         | 
| 346 | 
            +
            			ar_temp=args.ar_temp,
         | 
| 347 | 
            +
            			min_ar_temp=args.min_ar_temp,
         | 
| 348 | 
            +
            			top_p=args.top_p,
         | 
| 349 | 
            +
            			top_k=args.top_k,
         | 
| 350 | 
            +
            			min_p=args.min_p,
         | 
| 351 | 
            +
            			repetition_penalty=args.repetition_penalty,
         | 
| 352 | 
            +
            			repetition_penalty_decay=args.repetition_penalty_decay,
         | 
| 353 | 
            +
            			length_penalty=args.length_penalty,
         | 
| 354 | 
            +
            			mirostat_tau=args.mirostat_tau,
         | 
| 355 | 
            +
            			mirostat_eta=args.mirostat_eta,
         | 
| 356 | 
            +
            			dry_multiplier=args.dry_multiplier,
         | 
| 357 | 
            +
            			dry_base=args.dry_base,
         | 
| 358 | 
            +
            			dry_allowed_length=args.dry_allowed_length,
         | 
| 359 | 
            +
            			entropix_sampling=args.entropix_sampling,
         | 
| 360 | 
            +
            		)
         | 
| 361 | 
            +
            	
         | 
| 362 | 
            +
            	return text
         | 
| 363 | 
            +
             | 
| 364 | 
            +
            """
         | 
| 365 | 
            +
            @gradio_wrapper(inputs=layout["training"]["inputs"].keys())
         | 
| 366 | 
            +
            def do_training( progress=gr.Progress(track_tqdm=True), *args, **kwargs ):
         | 
| 367 | 
            +
            	while True:
         | 
| 368 | 
            +
            		metrics = next(it)
         | 
| 369 | 
            +
            		yield metrics
         | 
| 370 | 
            +
            """	
         | 
| 371 | 
            +
             | 
| 372 | 
            +
            # setup args
         | 
| 373 | 
            +
            parser = argparse.ArgumentParser(allow_abbrev=False)
         | 
| 374 | 
            +
            parser.add_argument("--yaml", type=Path, default=os.environ.get('VALLE_YAML', None)) # os environ so it can be specified in a HuggingFace Space too
         | 
| 375 | 
            +
            parser.add_argument("--model", type=Path, default=os.environ.get('VALLE_MODEL', None)) # os environ so it can be specified in a HuggingFace Space too
         | 
| 376 | 
            +
            parser.add_argument("--listen", default=None, help="Path for Gradio to listen on")
         | 
| 377 | 
            +
            parser.add_argument("--share", action="store_true")
         | 
| 378 | 
            +
            parser.add_argument("--render_markdown", action="store_true", default="VALLE_YAML" in os.environ)
         | 
| 379 | 
            +
            args, unknown = parser.parse_known_args()
         | 
| 380 | 
            +
             | 
| 381 | 
            +
            args.listen_host = None
         | 
| 382 | 
            +
            args.listen_port = None
         | 
| 383 | 
            +
            args.listen_path = None
         | 
| 384 | 
            +
            if args.listen:
         | 
| 385 | 
            +
            	try:
         | 
| 386 | 
            +
            		match = re.findall(r"^(?:(.+?):(\d+))?(\/.*?)?$", args.listen)[0]
         | 
| 387 | 
            +
             | 
| 388 | 
            +
            		args.listen_host = match[0] if match[0] != "" else "127.0.0.1"
         | 
| 389 | 
            +
            		args.listen_port = match[1] if match[1] != "" else None
         | 
| 390 | 
            +
            		args.listen_path = match[2] if match[2] != "" else "/"
         | 
| 391 | 
            +
            	except Exception as e:
         | 
| 392 | 
            +
            		pass
         | 
| 393 | 
            +
             | 
| 394 | 
            +
            if args.listen_port is not None:
         | 
| 395 | 
            +
            	args.listen_port = int(args.listen_port)
         | 
| 396 | 
            +
            	if args.listen_port == 0:
         | 
| 397 | 
            +
            		args.listen_port = None
         | 
| 398 | 
            +
             | 
| 399 | 
            +
            # setup gradio
         | 
| 400 | 
            +
            ui = gr.Blocks()
         | 
| 401 | 
            +
            with ui:
         | 
| 402 | 
            +
            	with gr.Tab("Inference"):
         | 
| 403 | 
            +
            		with gr.Tab("Text-to-Speech"):
         | 
| 404 | 
            +
            			with gr.Row():
         | 
| 405 | 
            +
            				with gr.Column(scale=8):
         | 
| 406 | 
            +
            					layout["inference_tts"]["inputs"]["text"] = gr.Textbox(lines=5, value=get_random_prompt, label="Input Prompt")
         | 
| 407 | 
            +
            			with gr.Row():
         | 
| 408 | 
            +
            				with gr.Column(scale=1):
         | 
| 409 | 
            +
            					layout["inference_tts"]["inputs"]["reference"] = gr.Audio(label="Audio Input", sources=["upload"], type="filepath") #, info="Reference audio for TTS")
         | 
| 410 | 
            +
            					# layout["inference_tts"]["stop"] = gr.Button(value="Stop")
         | 
| 411 | 
            +
            					layout["inference_tts"]["outputs"]["output"] = gr.Audio(label="Output")
         | 
| 412 | 
            +
            					layout["inference_tts"]["buttons"]["inference"] = gr.Button(value="Inference")
         | 
| 413 | 
            +
            				with gr.Column(scale=7):
         | 
| 414 | 
            +
            					with gr.Tab("Basic Settings"):
         | 
| 415 | 
            +
            						with gr.Row():
         | 
| 416 | 
            +
            							layout["inference_tts"]["inputs"]["max-seconds"] = gr.Slider(value=12, minimum=1, maximum=32, step=0.1, label="Maximum Seconds", info="Limits how many steps to perform in the AR pass.")
         | 
| 417 | 
            +
            							layout["inference_tts"]["inputs"]["input-prompt-length"] = gr.Slider(value=5.0, minimum=0.0, maximum=12.0, step=0.05, label="Input Prompt Repeat/Trim Length", info="Repeats and trims the input prompt down to X seconds. Set 0 to disable.")
         | 
| 418 | 
            +
            						with gr.Row():
         | 
| 419 | 
            +
            							layout["inference_tts"]["inputs"]["ar-temp"] = gr.Slider(value=0.5, minimum=0.0, maximum=1.5, step=0.05, label="Temperature (AR)", info="Modifies the randomness from the samples in the AR. (0 to greedy* sample)")
         | 
| 420 | 
            +
            							layout["inference_tts"]["inputs"]["nar-temp"] = gr.Slider(value=0.0, minimum=0.0, maximum=1.5, step=0.05, label="Temperature (NAR)", info="Modifies the randomness from the samples in the NAR. (0 to greedy sample)")
         | 
| 421 | 
            +
            						with gr.Row():
         | 
| 422 | 
            +
            							layout["inference_tts"]["inputs"]["language"] = gr.Dropdown(choices=get_languages(), label="Language", value="en")
         | 
| 423 | 
            +
            					with gr.Tab("Sampler Settings"):
         | 
| 424 | 
            +
            						with gr.Row():
         | 
| 425 | 
            +
            							layout["inference_tts"]["inputs"]["top-p"] = gr.Slider(value=1.0, minimum=0.0, maximum=1.0, step=0.05, label="Top P", info=r"Limits the samples that are outside the top P% of probabilities.")
         | 
| 426 | 
            +
            							layout["inference_tts"]["inputs"]["top-k"] = gr.Slider(value=0, minimum=0, maximum=1024, step=1, label="Top K", info="Limits the samples to the top K of probabilities.")
         | 
| 427 | 
            +
            							layout["inference_tts"]["inputs"]["min-p"] = gr.Slider(value=0.0, minimum=0.0, maximum=1.0, step=0.05, label="Min P")
         | 
| 428 | 
            +
            							layout["inference_tts"]["inputs"]["beam-width"] = gr.Slider(value=0, minimum=0, maximum=32, step=1, label="Beam Width", info="Number of branches to search through for beam search sampling.")
         | 
| 429 | 
            +
            						with gr.Row():
         | 
| 430 | 
            +
            							layout["inference_tts"]["inputs"]["repetition-penalty"] = gr.Slider(value=1.5, minimum=-2.0, maximum=2.0, step=0.05, label="Repetition Penalty", info="Incurs a penalty to tokens based on how often they appear in a sequence.")
         | 
| 431 | 
            +
            							layout["inference_tts"]["inputs"]["repetition-penalty-decay"] = gr.Slider(value=0.0, minimum=-2.0, maximum=2.0, step=0.05, label="Repetition Penalty Length Decay", info="Modifies the reptition penalty based on how far back in time the token appeared in the sequence.")
         | 
| 432 | 
            +
            							layout["inference_tts"]["inputs"]["length-penalty"] = gr.Slider(value=0.0, minimum=-2.0, maximum=2.0, step=0.05, label="Length Penalty", info="(AR only) Modifies the probability of a stop token based on the current length of the sequence.")
         | 
| 433 | 
            +
            						with gr.Row():
         | 
| 434 | 
            +
            							layout["inference_tts"]["inputs"]["mirostat-tau"] = gr.Slider(value=0.0, minimum=0.0, maximum=8.0, step=0.05, label="Mirostat τ (Tau)", info="The \"surprise\" value when performing mirostat sampling. 0 to disable.")
         | 
| 435 | 
            +
            							layout["inference_tts"]["inputs"]["mirostat-eta"] = gr.Slider(value=0.0, minimum=0.0, maximum=2.0, step=0.05, label="Mirostat η (Eta)", info="The \"learning rate\" during mirostat sampling applied to the maximum surprise.")
         | 
| 436 | 
            +
            						with gr.Row():
         | 
| 437 | 
            +
            							layout["inference_tts"]["inputs"]["dry-multiplier"] = gr.Slider(value=0.0, minimum=0.0, maximum=8.0, step=0.05, label="DRY Multiplier", info="The multiplying factor for the DRY score penalty (0 to disable DRY sampling).")
         | 
| 438 | 
            +
            							layout["inference_tts"]["inputs"]["dry-base"] = gr.Slider(value=1.75, minimum=0.0, maximum=8.0, step=0.05, label="DRY Base", info="The base of the exponent in the DRY score penalty")
         | 
| 439 | 
            +
            							layout["inference_tts"]["inputs"]["dry-allowed-length"] = gr.Slider(value=2, minimum=0, maximum=75, step=1, label="Allowed Length", info="The maximimum length a token can be to perform DRY penalty with.")
         | 
| 440 | 
            +
            					if cfg.experimental:
         | 
| 441 | 
            +
            						with gr.Tab("Experimental Settings"):
         | 
| 442 | 
            +
            							with gr.Row():
         | 
| 443 | 
            +
            								layout["inference_tts"]["inputs"]["max-nar-levels"] = gr.Slider(value=7, minimum=0, maximum=7, step=1, label="Max NAR Levels", info="Limits how many steps to perform in the NAR pass.")
         | 
| 444 | 
            +
            								layout["inference_tts"]["inputs"]["input-prompt-prefix"] = gr.Checkbox(label="Input Prompt as Prefix", info="Treats the input prompt clip as the prefix of the generated sequence.")
         | 
| 445 | 
            +
            							with gr.Row():
         | 
| 446 | 
            +
            								layout["inference_tts"]["inputs"]["prefix-silence"] = gr.Slider(value=0.0, minimum=0.0, maximum=1.0, step=0.05, label="Silence Prefix Duration", info="Amount of silence to prefix to the output response before beginning inference.")
         | 
| 447 | 
            +
            							with gr.Row():
         | 
| 448 | 
            +
            								layout["inference_tts"]["inputs"]["dynamic-sampling"] = gr.Checkbox(label="Dynamic Temperature", info="Dynamically adjusts the temperature based on the highest confident predicted token per sampling step.")
         | 
| 449 | 
            +
            								layout["inference_tts"]["inputs"]["entropix-sampling"] = gr.Checkbox(label="Entropix Sampling", info="Dynamically samples based on entropy/varentropy values from the logits / attention scores.")
         | 
| 450 | 
            +
            							with gr.Row():
         | 
| 451 | 
            +
            								layout["inference_tts"]["inputs"]["layer-skip"] = gr.Checkbox(label="Layer Skip", info="Performs self-speculative early exit 'sampling'")
         | 
| 452 | 
            +
            								layout["inference_tts"]["inputs"]["refine-on-stop"] = gr.Checkbox(label="Refine on <stop>", info="Uses the last step's logits for the AR sequence instead.")
         | 
| 453 | 
            +
            							with gr.Row():
         | 
| 454 | 
            +
            								layout["inference_tts"]["inputs"]["layer-skip-exit-layer"] = gr.Slider(value=11, minimum=0, maximum=11, step=1, label="Layer Skip Exit Layer", info="Maximum model layer to exit early from.")
         | 
| 455 | 
            +
            								layout["inference_tts"]["inputs"]["layer-skip-entropy-threshold"] = gr.Slider(value=0.1, minimum=0, maximum=1.0, step=0.01, label="Layer Skip Entropy Threshold", info="Entropy threshold for early-exit")
         | 
| 456 | 
            +
            								layout["inference_tts"]["inputs"]["layer-skip-varentropy-threshold"] = gr.Slider(value=0.1, minimum=0, maximum=1.0, step=0.01, label="Layer Skip Varentropy Threshold", info="Varentropy threshold for early-exit")
         | 
| 457 | 
            +
            						
         | 
| 458 | 
            +
             | 
| 459 | 
            +
            		layout["inference_tts"]["buttons"]["inference"].click(
         | 
| 460 | 
            +
            			fn=do_inference_tts,
         | 
| 461 | 
            +
            			inputs=[ x for x in layout["inference_tts"]["inputs"].values() if x is not None],
         | 
| 462 | 
            +
            			outputs=[ x for x in layout["inference_tts"]["outputs"].values() if x is not None]
         | 
| 463 | 
            +
            		)
         | 
| 464 | 
            +
             | 
| 465 | 
            +
            		with gr.Tab("Speech to Text"):
         | 
| 466 | 
            +
            			with gr.Row():
         | 
| 467 | 
            +
            				with gr.Column(scale=8):
         | 
| 468 | 
            +
            					layout["inference_stt"]["outputs"]["ouput"] = gr.Textbox(lines=1, label="Output Transcription")
         | 
| 469 | 
            +
            			with gr.Row():
         | 
| 470 | 
            +
            				with gr.Column(scale=1):
         | 
| 471 | 
            +
            					layout["inference_stt"]["inputs"]["reference"] = gr.Audio(label="Audio Input", sources=["upload"], type="filepath") #, info="Reference audio for TTS")
         | 
| 472 | 
            +
            					# layout["inference_stt"]["stop"] = gr.Button(value="Stop")
         | 
| 473 | 
            +
            					layout["inference_stt"]["buttons"]["inference"] = gr.Button(value="Inference")
         | 
| 474 | 
            +
            				with gr.Column(scale=7):
         | 
| 475 | 
            +
            					with gr.Tab("Basic Settings"):
         | 
| 476 | 
            +
            						with gr.Row():
         | 
| 477 | 
            +
            							layout["inference_stt"]["inputs"]["ar-temp"] = gr.Slider(value=0.0, minimum=0.0, maximum=1.5, step=0.05, label="Temperature (AR)", info="Modifies the randomness from the samples in the AR. (0 to greedy sample)")
         | 
| 478 | 
            +
            						with gr.Row():
         | 
| 479 | 
            +
            							layout["inference_stt"]["inputs"]["dynamic-sampling"] = gr.Checkbox(label="Dynamic Temperature", info="Dynamically adjusts the temperature based on the highest confident predicted token per sampling step.")
         | 
| 480 | 
            +
            							layout["inference_stt"]["inputs"]["language"] = gr.Dropdown(choices=get_languages(), label="Language", value="en")
         | 
| 481 | 
            +
            					with gr.Tab("Sampler Settings"):
         | 
| 482 | 
            +
            						with gr.Row():
         | 
| 483 | 
            +
            							layout["inference_stt"]["inputs"]["top-p"] = gr.Slider(value=1.0, minimum=0.0, maximum=1.0, step=0.05, label="Top P", info=r"Limits the samples that are outside the top P% of probabilities.")
         | 
| 484 | 
            +
            							layout["inference_stt"]["inputs"]["top-k"] = gr.Slider(value=0, minimum=0, maximum=1024, step=1, label="Top K", info="Limits the samples to the top K of probabilities.")
         | 
| 485 | 
            +
            							layout["inference_stt"]["inputs"]["min-p"] = gr.Slider(value=0.0, minimum=0.0, maximum=1.0, step=0.05, label="Min P")
         | 
| 486 | 
            +
            							layout["inference_stt"]["inputs"]["beam-width"] = gr.Slider(value=0, minimum=0, maximum=32, step=1, label="Beam Width", info="Number of branches to search through for beam search sampling.")
         | 
| 487 | 
            +
            						with gr.Row():
         | 
| 488 | 
            +
            							layout["inference_stt"]["inputs"]["repetition-penalty"] = gr.Slider(value=1.25, minimum=-2.0, maximum=2.0, step=0.05, label="Repetition Penalty", info="Incurs a penalty to tokens based on how often they appear in a sequence.")
         | 
| 489 | 
            +
            							layout["inference_stt"]["inputs"]["repetition-penalty-decay"] = gr.Slider(value=0.0, minimum=-2.0, maximum=2.0, step=0.05, label="Repetition Penalty Length Decay", info="Modifies the reptition penalty based on how far back in time the token appeared in the sequence.")
         | 
| 490 | 
            +
            							layout["inference_stt"]["inputs"]["length-penalty"] = gr.Slider(value=0.0, minimum=-2.0, maximum=2.0, step=0.05, label="Length Penalty", info="(AR only) Modifies the probability of a stop token based on the current length of the sequence.")
         | 
| 491 | 
            +
            						with gr.Row():
         | 
| 492 | 
            +
            							layout["inference_stt"]["inputs"]["mirostat-tau"] = gr.Slider(value=0.0, minimum=0.0, maximum=8.0, step=0.05, label="Mirostat τ (Tau)", info="The \"surprise\" value when performing mirostat sampling. 0 to disable.")
         | 
| 493 | 
            +
            							layout["inference_stt"]["inputs"]["mirostat-eta"] = gr.Slider(value=0.0, minimum=0.0, maximum=2.0, step=0.05, label="Mirostat η (Eta)", info="The \"learning rate\" during mirostat sampling applied to the maximum surprise.")
         | 
| 494 | 
            +
            						with gr.Row():
         | 
| 495 | 
            +
            							layout["inference_stt"]["inputs"]["dry-multiplier"] = gr.Slider(value=0.0, minimum=0.0, maximum=8.0, step=0.05, label="DRY Multiplier", info="The multiplying factor for the DRY score penalty (0 to disable DRY sampling).")
         | 
| 496 | 
            +
            							layout["inference_stt"]["inputs"]["dry-base"] = gr.Slider(value=1.75, minimum=0.0, maximum=8.0, step=0.05, label="DRY Base", info="The base of the exponent in the DRY score penalty")
         | 
| 497 | 
            +
            							layout["inference_stt"]["inputs"]["dry-allowed-length"] = gr.Slider(value=2, minimum=0, maximum=75, step=1, label="Allowed Length", info="The maximimum length a token can be to perform DRY penalty with.")
         | 
| 498 | 
            +
             | 
| 499 | 
            +
            		layout["inference_stt"]["buttons"]["inference"].click(
         | 
| 500 | 
            +
            			fn=do_inference_stt,
         | 
| 501 | 
            +
            			inputs=[ x for x in layout["inference_stt"]["inputs"].values() if x is not None],
         | 
| 502 | 
            +
            			outputs=[ x for x in layout["inference_stt"]["outputs"].values() if x is not None]
         | 
| 503 | 
            +
            		)
         | 
| 504 | 
            +
             | 
| 505 | 
            +
            		
         | 
| 506 | 
            +
            	"""
         | 
| 507 | 
            +
            	with gr.Tab("Training"):
         | 
| 508 | 
            +
            		with gr.Row():
         | 
| 509 | 
            +
            			with gr.Column(scale=1):
         | 
| 510 | 
            +
            				layout["training"]["outputs"]["console"] = gr.Textbox(lines=8, label="Console Log")
         | 
| 511 | 
            +
            		with gr.Row():
         | 
| 512 | 
            +
            			with gr.Column(scale=1):
         | 
| 513 | 
            +
            				layout["training"]["buttons"]["train"] = gr.Button(value="Train")
         | 
| 514 | 
            +
             | 
| 515 | 
            +
            		layout["training"]["buttons"]["train"].click(
         | 
| 516 | 
            +
            			fn=do_training,
         | 
| 517 | 
            +
            			outputs=[ x for x in layout["training"]["outputs"].values() if x is not None],
         | 
| 518 | 
            +
            		)
         | 
| 519 | 
            +
            	"""
         | 
| 520 | 
            +
             | 
| 521 | 
            +
            	if not USING_SPACES:
         | 
| 522 | 
            +
            		with gr.Tab("Dataset"):
         | 
| 523 | 
            +
            			with gr.Row():
         | 
| 524 | 
            +
            				with gr.Column(scale=7):
         | 
| 525 | 
            +
            					layout["dataset"]["outputs"]["transcription"] = gr.Textbox(lines=5, label="Sample Metadata")
         | 
| 526 | 
            +
            				with gr.Column(scale=1):
         | 
| 527 | 
            +
            					layout["dataset"]["inputs"]["speaker"] = gr.Dropdown(choices=get_speakers(), label="Speakers")
         | 
| 528 | 
            +
            					layout["dataset"]["outputs"]["audio"] = gr.Audio(label="Output")
         | 
| 529 | 
            +
            					layout["dataset"]["buttons"]["sample"] = gr.Button(value="Sample")
         | 
| 530 | 
            +
             | 
| 531 | 
            +
            				layout["dataset"]["buttons"]["sample"].click(
         | 
| 532 | 
            +
            					fn=load_sample,
         | 
| 533 | 
            +
            					inputs=[ x for x in layout["dataset"]["inputs"].values() if x is not None],
         | 
| 534 | 
            +
            					outputs=[ x for x in layout["dataset"]["outputs"].values() if x is not None],
         | 
| 535 | 
            +
            				)
         | 
| 536 | 
            +
             | 
| 537 | 
            +
            	if not USING_SPACES:
         | 
| 538 | 
            +
            		with gr.Tab("Settings"):
         | 
| 539 | 
            +
            			with gr.Row():
         | 
| 540 | 
            +
            				with gr.Column(scale=7):
         | 
| 541 | 
            +
            					with gr.Row():
         | 
| 542 | 
            +
            						layout["settings"]["inputs"]["models"] = gr.Dropdown(choices=get_model_paths(), value=args.yaml or args.model, label="Model")
         | 
| 543 | 
            +
            						layout["settings"]["inputs"]["device"] = gr.Dropdown(choices=get_devices(), value="cuda:0", label="Device")
         | 
| 544 | 
            +
            						layout["settings"]["inputs"]["dtype"] = gr.Dropdown(choices=get_dtypes(), value="auto", label="Precision")
         | 
| 545 | 
            +
            						layout["settings"]["inputs"]["attentions"] = gr.Dropdown(choices=get_attentions(), value="auto", label="Attentions")
         | 
| 546 | 
            +
            				with gr.Column(scale=1):
         | 
| 547 | 
            +
            					layout["settings"]["buttons"]["load"] = gr.Button(value="Load Model")
         | 
| 548 | 
            +
             | 
| 549 | 
            +
            				layout["settings"]["buttons"]["load"].click(
         | 
| 550 | 
            +
            					fn=load_model,
         | 
| 551 | 
            +
            					inputs=[ x for x in layout["settings"]["inputs"].values() if x is not None],
         | 
| 552 | 
            +
            					outputs=[ x for x in layout["settings"]["outputs"].values() if x is not None],
         | 
| 553 | 
            +
            				)
         | 
| 554 | 
            +
             | 
| 555 | 
            +
            	if os.path.exists("README.md") and args.render_markdown:
         | 
| 556 | 
            +
            		md = open("README.md", "r", encoding="utf-8").read()
         | 
| 557 | 
            +
            		# remove HF's metadata
         | 
| 558 | 
            +
            		if md.startswith("---\n"):
         | 
| 559 | 
            +
            			md = "".join(md.split("---")[2:])
         | 
| 560 | 
            +
            		gr.Markdown(md)
         | 
| 561 | 
            +
             | 
| 562 | 
            +
            def start( lock=True ):
         | 
| 563 | 
            +
            	setup_logging()
         | 
| 564 | 
            +
             | 
| 565 | 
            +
            	if not USING_SPACES:
         | 
| 566 | 
            +
            		ui.queue(max_size=8)
         | 
| 567 | 
            +
            		ui.launch(share=args.share, server_name=args.listen_host, server_port=args.listen_port, prevent_thread_lock=not lock)
         | 
| 568 | 
            +
            	else:
         | 
| 569 | 
            +
            		ui.queue().launch()
         | 
| 570 | 
            +
             | 
| 571 | 
            +
            if __name__ == "__main__":
         | 
| 572 | 
            +
            	start()
         | 
