Spaces:
Running
Running
File size: 1,082 Bytes
1e5f3d4 | 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 34 35 36 37 38 39 40 | import gradio as gr
from inference import predict
import torch
from huggingface_hub import hf_hub_download
# This pulls just the model file from your specific repo
model_path = hf_hub_download(repo_id="PRUTHVIn/vqa_project", filename="weights/vqa_model.pth")
# Now load it into your model class (example)
# model.load_state_dict(torch.load(model_path))
def vqa_interface(image, question):
try:
if image is None or question.strip() == "":
return "Please upload an image and enter a question."
answer = predict(image, question)
return answer
except Exception as e:
print("ERROR:", str(e))
return f"Error: {str(e)}"
iface = gr.Interface(
fn=vqa_interface,
inputs=[
gr.Image(type="filepath", label="Upload Image"),
gr.Textbox(
label="Ask a Question",
placeholder="e.g. What is in the image?"
)
],
outputs=gr.Textbox(label="Answer"),
title="🧠 Smart Visual Question Answering System",
theme="soft"
)
if __name__ == "__main__":
iface.launch() |