Update app.py
Browse files
app.py
CHANGED
|
@@ -1,4 +1,25 @@
|
|
|
|
|
| 1 |
import streamlit as st
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
-
st.title("
|
| 4 |
-
st.write("
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# app.py
|
| 2 |
import streamlit as st
|
| 3 |
+
from transformers import BlipProcessor, BlipForConditionalGeneration
|
| 4 |
+
from PIL import Image
|
| 5 |
+
import torch
|
| 6 |
|
| 7 |
+
st.title("AI Image Caption Generator")
|
| 8 |
+
st.write("Upload an image and get a caption generated by an AI model!")
|
| 9 |
+
|
| 10 |
+
uploaded_file = st.file_uploader("Upload an image", type=["jpg", "png", "jpeg"])
|
| 11 |
+
|
| 12 |
+
if uploaded_file:
|
| 13 |
+
image = Image.open(uploaded_file).convert('RGB')
|
| 14 |
+
st.image(image, caption="Uploaded Image", use_column_width=True)
|
| 15 |
+
|
| 16 |
+
st.write("Generating caption...")
|
| 17 |
+
|
| 18 |
+
processor = BlipProcessor.from_pretrained("Salesforce/blip-image-captioning-base")
|
| 19 |
+
model = BlipForConditionalGeneration.from_pretrained("Salesforce/blip-image-captioning-base")
|
| 20 |
+
|
| 21 |
+
inputs = processor(image, return_tensors="pt")
|
| 22 |
+
out = model.generate(**inputs)
|
| 23 |
+
caption = processor.decode(out[0], skip_special_tokens=True)
|
| 24 |
+
|
| 25 |
+
st.success(f"π Caption: {caption}")
|