File size: 841 Bytes
24d7db6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
from transformers import BlipProcessor, BlipForQuestionAnswering
from PIL import Image

# 모델 로드
processor = BlipProcessor.from_pretrained("Salesforce/blip-vqa-base")
model = BlipForQuestionAnswering.from_pretrained("Salesforce/blip-vqa-base")

def answer_question(image, question):
    inputs = processor(image, question, return_tensors="pt")
    out = model.generate(**inputs)
    answer = processor.decode(out[0], skip_special_tokens=True)
    return answer

# Gradio UI
demo = gr.Interface(
    fn=answer_question,
    inputs=[
        gr.Image(type="pil"),
        gr.Textbox(label="질문 입력")
    ],
    outputs="text",
    title="🖼️ 이미지 질문 답변 AI",
    description="이미지를 업로드하고 질문을 입력하면 AI가 답변합니다."
)

demo.launch()