Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -21,7 +21,7 @@ app = FastAPI()
|
|
21 |
vqa_pipeline = pipeline("image-to-text", model="Salesforce/blip-vqa-base")
|
22 |
code_generator = pipeline("text-generation", model="openai-community/gpt2-medium")
|
23 |
table_analyzer = pipeline("table-question-answering", model="google/tapas-large-finetuned-wtq")
|
24 |
-
qa_pipeline = pipeline("
|
25 |
|
26 |
# β
Functions for Document & Image QA
|
27 |
def extract_text_from_pdf(pdf_file):
|
@@ -74,16 +74,21 @@ def answer_question_from_document(file, question):
|
|
74 |
if not text:
|
75 |
return "No text extracted from the document."
|
76 |
|
77 |
-
|
78 |
-
|
|
|
|
|
|
|
79 |
|
80 |
def answer_question_from_image(image, question):
|
81 |
image_text = extract_text_from_image(image)
|
82 |
if not image_text:
|
83 |
return "No text detected in the image."
|
84 |
|
85 |
-
|
86 |
-
|
|
|
|
|
87 |
|
88 |
# β
Gradio UI for Document & Image QA
|
89 |
doc_interface = gr.Interface(
|
|
|
21 |
vqa_pipeline = pipeline("image-to-text", model="Salesforce/blip-vqa-base")
|
22 |
code_generator = pipeline("text-generation", model="openai-community/gpt2-medium")
|
23 |
table_analyzer = pipeline("table-question-answering", model="google/tapas-large-finetuned-wtq")
|
24 |
+
qa_pipeline = pipeline("text2text-generation", model="google/flan-t5-large") # β
FIXED
|
25 |
|
26 |
# β
Functions for Document & Image QA
|
27 |
def extract_text_from_pdf(pdf_file):
|
|
|
74 |
if not text:
|
75 |
return "No text extracted from the document."
|
76 |
|
77 |
+
# β
FLAN-T5 expects input in a specific format
|
78 |
+
input_text = f"Question: {question} Context: {text}"
|
79 |
+
response = qa_pipeline(input_text)
|
80 |
+
|
81 |
+
return response[0]["generated_text"] # β
FIXED OUTPUT EXTRACTION
|
82 |
|
83 |
def answer_question_from_image(image, question):
|
84 |
image_text = extract_text_from_image(image)
|
85 |
if not image_text:
|
86 |
return "No text detected in the image."
|
87 |
|
88 |
+
input_text = f"Question: {question} Context: {image_text}"
|
89 |
+
response = qa_pipeline(input_text)
|
90 |
+
|
91 |
+
return response[0]["generated_text"]
|
92 |
|
93 |
# β
Gradio UI for Document & Image QA
|
94 |
doc_interface = gr.Interface(
|