Spaces:
Sleeping
Sleeping
import streamlit as st | |
from io import StringIO | |
from PIL import Image | |
import numpy as np | |
from transformers import pipeline | |
from helper.image_helper import to_base64 | |
pipe = pipeline("image-to-text", | |
model="Salesforce/blip-image-captioning-base") | |
def process_file(): | |
stringio = StringIO(uploaded_file.getvalue().decode("utf-8")) | |
txt = launch(stringio) | |
st.write(txt) | |
def launch(input): | |
out = pipe(input) | |
return out[0]['generated_text'] | |
# uploaded_file = st.file_uploader("Choose a file", on_change=process_file) | |
uploaded_file = st.file_uploader("Choose a file") | |
if uploaded_file is not None: | |
# st.image(uploaded_file) | |
image = Image.open(uploaded_file) | |
# bytes_data = uploaded_file.getvalue() | |
base64 = to_base64(uploaded_file) | |
st.image(base64) | |
txt = launch(base64) | |
st.write(txt) | |
# iface = gr.Interface(launch, | |
# inputs=gr.Image(type='pil'), | |
# outputs="text") | |
# iface.launch() |