Spaces:
Runtime error
Runtime error
| import gradio as gr | |
| import torch | |
| from transformers import AutoProcessor, LlavaForConditionalGeneration | |
| MODEL_NAME = "Declan1/llava-v1.6-mistral-7b-sydneyfish-a100" | |
| # Load processor (handles image + text formatting) | |
| processor = AutoProcessor.from_pretrained(MODEL_NAME) | |
| # Load model (Vision + Language fused) | |
| model = LlavaForConditionalGeneration.from_pretrained( | |
| MODEL_NAME, | |
| torch_dtype=torch.float16, | |
| device_map="auto" | |
| ) | |
| def chat(image, prompt): | |
| # Process inputs | |
| inputs = processor(prompt, images=image, return_tensors="pt").to(model.device) | |
| # Generate output | |
| output = model.generate(**inputs, max_new_tokens=300) | |
| # Decode to readable text | |
| response = processor.decode(output[0], skip_special_tokens=True) | |
| return response | |
| # Simple UI | |
| interface = gr.Interface( | |
| fn=chat, | |
| inputs=[gr.Image(type="pil", label="Image"), gr.Textbox(label="Prompt")], | |
| outputs=gr.Textbox(label="Response"), | |
| title="SydneyFish LLaVA (Mistral 7B)", | |
| description="Upload an image and ask it something." | |
| ) | |
| interface.launch() | |