Spaces:
Running
Running
Revert "Return a list of predicted labels"
Browse filesThis reverts commit 72d940356accfca18261d089a669501e0c0ff778.
6 unmodified lines7891011121351 unmodified lines656667686970717210 unmodified lines838485868788899091929394959618 unmodified lines1151161171181191201211221231246 unmodified linesimport osimport pathlibimport tarfileimport tempfileimport deepdanbooru as ddimport gradio as gr51 unmodified linesdef predict(image: PIL.Image.Image, score_threshold: float,model: tf.keras.Model,labels: list[str]) -> tuple[dict[str, float], str]:_, height, width, _ = model.input_shapeimage = np.asarray(image)image = tf.image.resize(image,10 unmodified linesif prob < score_threshold:continueres[label] = probsorted_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.namedef main():18 unmodified linesvalue=args.score_threshold,label='Score Threshold'),],[gr.Label(label='Output'),gr.File(label='Tag List'),],examples=examples,title=TITLE,description=DESCRIPTION,6 unmodified lines78910111251 unmodified lines6465666768697010 unmodified lines8182838485868718 unmodified lines1061071081091101111126 unmodified linesimport osimport pathlibimport tarfileimport deepdanbooru as ddimport gradio as gr51 unmodified linesdef predict(image: PIL.Image.Image, score_threshold: float,model: tf.keras.Model, labels: list[str]) -> dict[str, float]:_, height, width, _ = model.input_shapeimage = np.asarray(image)image = tf.image.resize(image,10 unmodified linesif prob < score_threshold:continueres[label] = probreturn resdef main():18 unmodified linesvalue=args.score_threshold,label='Score Threshold'),],gr.Label(label='Output'),examples=examples,title=TITLE,description=DESCRIPTION,
app.py+3-15