ikraamkb commited on
Commit
f57a980
Β·
verified Β·
1 Parent(s): 94ce57e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -5
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("question-answering", model="google/flan-t5-large ") # βœ… FIXED MODEL
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
- response = qa_pipeline(question=question, context=text) # βœ… FIXED
78
- return response["answer"]
 
 
 
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
- response = qa_pipeline(question=question, context=image_text) # βœ… FIXED
86
- return response["answer"]
 
 
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(