File size: 821 Bytes
8f35db0
1838b80
8f35db0
 
1838b80
8f35db0
 
fec45e6
8f35db0
fec45e6
8f35db0
 
 
 
 
fec45e6
8f35db0
 
fec45e6
8f35db0
 
 
 
 
 
 
fec45e6
8f35db0
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
from PIL import Image
import gradio as gr
import requests
from transformers import AutoProcessor, BlipForQuestionAnswering

model = BlipForQuestionAnswering.from_pretrained("Salesforce/blip-vqa-base")
processor = AutoProcessor.from_pretrained("Salesforce/blip-vqa-base")

def generate_answer(text, image):

    text = text
    inputs = processor(images=image, text=text, return_tensors="pt")
    outputs = model.generate(**inputs)
    
    return processor.decode(outputs[0], skip_special_tokens=True)

text_input = gr.Textbox(lines=5, label="Enter text")
image_input = gr.Image(type="pil", label="Upload Image")

iface = gr.Interface(
    fn=generate_answer, 
    inputs=[text_input, image_input], 
    outputs="text",
    title="DD360-Bot-Multimodal",
    description="Enter text and upload an image"
)

iface.launch()