Spaces:
Runtime error
Runtime error
File size: 1,298 Bytes
e799242 | 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 | import streamlit as st
from transformers import BlipProcessor, BlipForQuestionAnswering
from PIL import Image
import torch
# 제목
st.title("🖼️ 이미지 질문 답변 AI")
st.write("이미지를 업로드하고 질문을 입력하면 AI가 답해줍니다!")
# 모델 로드 (한 번만 로드)
@st.cache_resource
def load_model():
processor = BlipProcessor.from_pretrained("Salesforce/blip-vqa-base")
model = BlipForQuestionAnswering.from_pretrained("Salesforce/blip-vqa-base")
return processor, model
processor, model = load_model()
# 이미지 업로드
uploaded_file = st.file_uploader("이미지를 업로드하세요", type=["jpg", "jpeg", "png"])
# 질문 입력
question = st.text_input("질문을 입력하세요 (예: 이 사진에 뭐가 있나요?)")
# 실행
if uploaded_file and question:
image = Image.open(uploaded_file).convert("RGB")
st.image(image, caption="업로드한 이미지", use_column_width=True)
if st.button("질문하기"):
with st.spinner("AI가 생각 중..."):
inputs = processor(image, question, return_tensors="pt")
out = model.generate(**inputs)
answer = processor.decode(out[0], skip_special_tokens=True)
st.success("완료!")
st.write("👉 답변:", answer) |