Spaces:
Running
Running
Revert "Return a list of predicted labels"
Browse filesThis reverts commit 72d940356accfca18261d089a669501e0c0ff778.
6 unmodified lines7891010111251 unmodified lines64656668696768697010 unmodified lines81828386878889909192938485868718 unmodified lines1061071081181191091201211101111126 unmodified linesimport osimport pathlibimport tarfileimport tempfile
import deepdanbooru as ddimport gradio as gr51 unmodified lines
def predict(image: PIL.Image.Image, score_threshold: float, model: tf.keras.Model, labels: list[str]) -> tuple[dict[str, float], str]: model: tf.keras.Model, labels: list[str]) -> dict[str, float]: _, height, width, _ = model.input_shape image = np.asarray(image) image = tf.image.resize(image,10 unmodified lines if prob < score_threshold: continue res[label] = prob
sorted_preds = sorted(res.items(), key=lambda x: -x[1]) out_path = tempfile.NamedTemporaryFile(suffix='.txt', delete=False) with open(out_path.name, 'w') as f: for key, _ in sorted_preds: f.write(f'{key}\n')
return res, out_path.name return res
def main():18 unmodified lines value=args.score_threshold, label='Score Threshold'), ], [ gr.Label(label='Output'), gr.Label(label='Output'), gr.File(label='Tag List'), ], examples=examples, title=TITLE, description=DESCRIPTION,app.py+3-15