import gradio as gr from transformers import AutoModelForImageTextToText, AutoProcessor from PIL import Image import torch model_id = "Rishabh3365/smolvlm2-blv-500m" processor = AutoProcessor.from_pretrained(model_id) model = AutoModelForImageTextToText.from_pretrained( model_id, torch_dtype=torch.float32 ) model.eval() def describe_scene(image, instruction): inputs = processor(images=image, text=instruction, return_tensors="pt") with torch.no_grad(): output = model.generate(**inputs, max_new_tokens=200) return processor.decode(output[0], skip_special_tokens=True) gr.Interface( fn=describe_scene, inputs=[ gr.Image(sources=["webcam", "upload"], type="pil", label="Capture / Upload"), gr.Textbox(value="What do you see? Describe for a blind person.", label="Instruction") ], outputs=gr.Textbox(label="BLV Navigation Response"), title="SmolVLM2 BLV Navigation Assistant", description="Captures a scene and describes it for blind and low-vision users." ).launch()