mestreamlit / pages /66_πŸ”₯_Torch.py
yuanjie
update
144a16c
raw
history blame
806 Bytes
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Project : Python.
# @File : 4_πŸ”₯_Torch
# @Time : 2022/9/23 上午11:40
# @Author : yuanjie
# @WeChat : meutils
# @Software : PyCharm
# @Description :
import streamlit as st
from transformers import pipeline
from PIL import Image
pipeline = pipeline(task="image-classification", model="julien-c/hotdog-not-hotdog")
st.title("Hot Dog? Or Not?")
file_name = st.file_uploader("Upload a hot dog candidate image")
if file_name is not None:
col1, col2 = st.columns(2)
image = Image.open(file_name)
col1.image(image, use_column_width=True)
predictions = pipeline(image)
col2.header("Probabilities")
for p in predictions:
col2.subheader(f"{p['label']}: {round(p['score'] * 100, 1)}%")