Spaces:
Sleeping
Sleeping
File size: 1,382 Bytes
6c33d37 |
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 |
import gradio as gr
from transformers.utils import logging
from transformers import BlipForQuestionAnswering, AutoProcessor
from PIL import Image
logging.set_verbosity_error()
# Load the model and processor
model = BlipForQuestionAnswering.from_pretrained("Salesforce/blip-vqa-base")
processor = AutoProcessor.from_pretrained("Salesforce/blip-vqa-base")
# Define a function to process inputs and generate outputs
def predict(image, question):
inputs = processor(image, question, return_tensors="pt")
out = model.generate(**inputs)
answer = processor.decode(out[0], skip_special_tokens=True)
return answer
# Create the Gradio interface with custom Markdown and HTML formatting
demo = gr.Interface(
fn=predict,
inputs=[
gr.Image(type="pil", label="Upload Image"),
gr.Textbox(label="Question", placeholder="Ask a question about the image")
],
outputs=gr.Textbox(label="Answer"),
description="<h1 style='text-align: center; font-family: Times New Roman;'>Visual Question Answering</h1> \
<p style='text-align: center; font-family: Times New Roman;'><strong>Model name:</strong> Salesforce/blip-vqa-base</p> \
<p style='text-align: center; font-family: Times New Roman;'><strong>Made by:</strong> MD MAHMUDUN NABI</p>"
)
# Launch the Gradio interface
demo.launch()
|