Spaces:
Runtime error
Runtime error
Download app.py from Rishabh3365/test: direct link, hf CLI and curl.
- Browser
- Download file 1.03 kB
-
https://huggingface.co/spaces/Rishabh3365/test/resolve/main/app.py
- Command line
-
hf download hf://spaces/Rishabh3365/test/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Rishabh3365/test/resolve/main/app.py
1.03 kB
| 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() |