FreshBench / gradio_samples /hf_space_test.py
jijivski
dynamically add choices
e2bf898
raw
history blame contribute delete
No virus
854 Bytes
# this need hugginface connection
import gradio as gr
from transformers import pipeline
pipeline = pipeline(task="image-classification", model="julien-c/hotdog-not-hotdog")
def predict(input_img):
predictions = pipeline(input_img)
return input_img, {p["label"]: p["score"] for p in predictions}
gradio_app = gr.Interface(
predict,
inputs=gr.Image(label="Select hot dog candidate", sources=['upload', 'webcam'], type="pil"),# upload means upload the image, webcam means use the camera,
# if I want to craw and drop the image, I can use the following code
# inputs=gr.Image(label="Select hot dog candidate", source='webcam', type="pil"),
outputs=[gr.Image(label="Processed Image"), gr.Label(label="Result", num_top_classes=2)],
title="Hot Dog? Or Not?",
)
if __name__ == "__main__":
gradio_app.launch(debug=True)