app.py
Browse files
app.py
CHANGED
|
@@ -1,20 +1,19 @@
|
|
| 1 |
-
# app.py
|
| 2 |
import tempfile
|
| 3 |
import gradio as gr
|
| 4 |
from main import load_artifacts_and_helpers, device
|
| 5 |
|
| 6 |
-
# Load model
|
| 7 |
final_pipeline, predict_fn, vocab, idx_to_answer, model, encode_fn = \
|
| 8 |
load_artifacts_and_helpers(prefix="vqa_custom", map_location=device)
|
| 9 |
|
| 10 |
def vqa_interface(image, question):
|
| 11 |
-
# image is a PIL image from Gradio
|
| 12 |
with tempfile.NamedTemporaryFile(suffix=".jpg") as f:
|
| 13 |
image.save(f.name)
|
| 14 |
answer = final_pipeline(
|
| 15 |
f.name,
|
| 16 |
question,
|
| 17 |
-
open_vqa_fn=None,
|
| 18 |
translate_fn=None
|
| 19 |
)
|
| 20 |
return answer
|
|
@@ -27,7 +26,7 @@ demo = gr.Interface(
|
|
| 27 |
],
|
| 28 |
outputs=gr.Textbox(label="Answer"),
|
| 29 |
title="VQA-RAD Demo",
|
| 30 |
-
description="Custom
|
| 31 |
)
|
| 32 |
|
| 33 |
if __name__ == "__main__":
|
|
|
|
|
|
|
| 1 |
import tempfile
|
| 2 |
import gradio as gr
|
| 3 |
from main import load_artifacts_and_helpers, device
|
| 4 |
|
| 5 |
+
# Load model and helpers once when the Space starts
|
| 6 |
final_pipeline, predict_fn, vocab, idx_to_answer, model, encode_fn = \
|
| 7 |
load_artifacts_and_helpers(prefix="vqa_custom", map_location=device)
|
| 8 |
|
| 9 |
def vqa_interface(image, question):
|
| 10 |
+
# image is a PIL image from Gradio
|
| 11 |
with tempfile.NamedTemporaryFile(suffix=".jpg") as f:
|
| 12 |
image.save(f.name)
|
| 13 |
answer = final_pipeline(
|
| 14 |
f.name,
|
| 15 |
question,
|
| 16 |
+
open_vqa_fn=None, # BLIP disabled in Space for speed
|
| 17 |
translate_fn=None
|
| 18 |
)
|
| 19 |
return answer
|
|
|
|
| 26 |
],
|
| 27 |
outputs=gr.Textbox(label="Answer"),
|
| 28 |
title="VQA-RAD Demo",
|
| 29 |
+
description="Custom ResNet18 + LSTM VQA model (top-50 answers)."
|
| 30 |
)
|
| 31 |
|
| 32 |
if __name__ == "__main__":
|