Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -9,6 +9,7 @@ import easyocr
|
|
9 |
import torch
|
10 |
import tempfile
|
11 |
import gradio as gr
|
|
|
12 |
|
13 |
app = FastAPI()
|
14 |
|
@@ -19,8 +20,8 @@ vqa_model = ViltForQuestionAnswering.from_pretrained("dandelin/vilt-b32-finetune
|
|
19 |
# Load image captioning model
|
20 |
captioner = pipeline("image-to-text", model="nlpconnect/vit-gpt2-image-captioning")
|
21 |
|
22 |
-
# Load EasyOCR reader
|
23 |
-
reader = easyocr.Reader(['en', 'fr'])
|
24 |
|
25 |
def classify_question(question: str):
|
26 |
question_lower = question.lower()
|
@@ -39,7 +40,7 @@ def answer_question_from_image(image, question):
|
|
39 |
|
40 |
if mode == "ocr":
|
41 |
try:
|
42 |
-
result = reader.readtext(image)
|
43 |
text = " ".join([entry[1] for entry in result])
|
44 |
answer = text.strip() or "No readable text found."
|
45 |
except Exception as e:
|
@@ -85,7 +86,7 @@ gui = gr.Interface(
|
|
85 |
gr.Textbox(label="Answer", lines=5),
|
86 |
gr.Audio(label="Answer (Audio)", type="filepath")
|
87 |
],
|
88 |
-
title="
|
89 |
description="Upload an image and ask a question. Works for OCR, captioning, and VQA."
|
90 |
)
|
91 |
|
@@ -93,4 +94,4 @@ app = gr.mount_gradio_app(app, gui, path="/")
|
|
93 |
|
94 |
@app.get("/")
|
95 |
def home():
|
96 |
-
return RedirectResponse(url="/")
|
|
|
9 |
import torch
|
10 |
import tempfile
|
11 |
import gradio as gr
|
12 |
+
import numpy as np
|
13 |
|
14 |
app = FastAPI()
|
15 |
|
|
|
20 |
# Load image captioning model
|
21 |
captioner = pipeline("image-to-text", model="nlpconnect/vit-gpt2-image-captioning")
|
22 |
|
23 |
+
# Load EasyOCR reader with English, French, Arabic
|
24 |
+
reader = easyocr.Reader(['en', 'fr', 'ar'])
|
25 |
|
26 |
def classify_question(question: str):
|
27 |
question_lower = question.lower()
|
|
|
40 |
|
41 |
if mode == "ocr":
|
42 |
try:
|
43 |
+
result = reader.readtext(np.array(image))
|
44 |
text = " ".join([entry[1] for entry in result])
|
45 |
answer = text.strip() or "No readable text found."
|
46 |
except Exception as e:
|
|
|
86 |
gr.Textbox(label="Answer", lines=5),
|
87 |
gr.Audio(label="Answer (Audio)", type="filepath")
|
88 |
],
|
89 |
+
title="🧐 Image QA with Voice",
|
90 |
description="Upload an image and ask a question. Works for OCR, captioning, and VQA."
|
91 |
)
|
92 |
|
|
|
94 |
|
95 |
@app.get("/")
|
96 |
def home():
|
97 |
+
return RedirectResponse(url="/")
|