Spaces:
Sleeping
Sleeping
File size: 1,000 Bytes
dcd311f 98ed57d dcd311f e3c1dfe 98ed57d 8343c4a e3c1dfe 8343c4a a827854 98ed57d e3c1dfe a827854 98ed57d 8343c4a 98ed57d 8343c4a dcd311f 8343c4a 98ed57d dcd311f e3c1dfe 8343c4a |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
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")
img= None
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:
img = Image.open(uploaded_file)
st.image(img)
# bytes_data = uploaded_file.getvalue()
# base64 = to_base64(uploaded_file)
# st.image(base64)
txt = launch(img)
st.write(txt)
# iface = gr.Interface(launch,
# inputs=gr.Image(type='pil'),
# outputs="text")
# iface.launch()
|