-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
38 lines (23 loc) · 1.07 KB
/
Copy pathmain.py
File metadata and controls
38 lines (23 loc) · 1.07 KB
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
import streamlit as st
from transformers import AutoProcessor, BlipForConditionalGeneration
from PIL import Image
# Load my_model from hugging face
model = BlipForConditionalGeneration.from_pretrained("StevenTrujillo/my-model")
# Load the processor (working on saving my own processor)
processor = AutoProcessor.from_pretrained("StevenTrujillo/my-processor")
# Title
st.title("AI Club Image Captioning Model")
# Header
st.header("Image Upload:")
# File uploader widget
uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])
if uploaded_file is not None:
# Display the uploaded image
st.image(uploaded_file, caption="Uploaded Image.", use_column_width=True)
image = Image.open(uploaded_file)
inputs = processor(images=image, return_tensors="pt").to('cpu')
pixel_values = inputs.pixel_values
generated_ids = model.generate(pixel_values=pixel_values, max_length=50)
generated_caption = processor.batch_decode(generated_ids, skip_special_tokens=True)[0]
st.subheader('Generated Image Caption:')
st.write(generated_caption)