フレームワークをstreamlitにするかどうか検討

#3
by terapyon - opened

GradioにDate pickerがないことがわかり、streamlitに変更するかどうか検討する。
https://github.com/gradio-app/gradio/issues/2029

  • Hugging Face spacesで使えることを確認
  • Date pickerがあるか?
  • 必要なコンポーネントがあるか?
  • デモアプリを作って試す

ugging Face spacesでStreamlitを使う

https://huggingface.co/docs/hub/spaces-sdks-streamlit

README.mdに以下を記載(バージョンは別途調査)

sdk: streamlit
sdk_version: 1.25.0 # The latest supported version

README.mdのメタデータ情報
https://huggingface.co/docs/hub/spaces-config-reference

All versions of Streamlit from 0.79.0 are supported.

Streamlitの最新版
https://pypi.org/project/streamlit/
1.25.0

気になる点

  • Spacesを作るときに gradio を選択したが、READMEのみの変更で適用できるか?

Streamlitのシンプルなアプリ

https://huggingface.co/docs/hub/spaces-sdks-streamlit

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)}%")

抜粋

import streamlit as st
st.title("Hot Dog? Or Not?")
col1, col2 = st.columns(2)
col2.header("Probabilities")
col2.subheader("")

その他の例

https://docs.streamlit.io/library/get-started/main-concepts#widgets

import streamlit as st
x = st.slider('x')  # 👈 this is a widget
st.write(x, 'squared is', x * x)

st.text_input("Your name", key="name")
# You can access the value at any point with:
st.session_state.name

https://docs.streamlit.io/library/get-started/main-concepts#show-progress

import streamlit as st
import time

'Starting a long computation...'

# Add a placeholder
latest_iteration = st.empty()
bar = st.progress(0)

for i in range(100):
  # Update the progress bar with each iteration.
  latest_iteration.text(f'Iteration {i+1}')
  bar.progress(i + 1)
  time.sleep(0.1)

'...and now we\'re done!'

streamlit を pipでインストールして、試したほうが良さそう。

streamlit run Hello.py

ワイヤーフレームを作って、エレメントを整理すればできそう。

terapyon changed discussion status to closed

Sign up or log in to comment