ikraamkb commited on
Commit
6bf4ee9
·
verified ·
1 Parent(s): 875917f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -7
app.py CHANGED
@@ -110,13 +110,22 @@ def answer_question_from_document(file, question):
110
  return response[0]["generated_text"]
111
 
112
  def answer_question_from_image(image, question):
113
- print("🖼️ Generating caption for image...")
114
- caption = image_captioning_pipeline(image)[0]['generated_text']
115
-
116
- print("🤖 Answering question based on caption...")
117
- response = doc_qa_pipeline(f"Question: {question}\nContext: {caption}")
118
-
119
- return response[0]["generated_text"]
 
 
 
 
 
 
 
 
 
120
 
121
  # Gradio UI for Document & Image QA
122
  doc_interface = gr.Interface(
 
110
  return response[0]["generated_text"]
111
 
112
  def answer_question_from_image(image, question):
113
+ try:
114
+ print("🖼️ Converting image for processing...")
115
+ if isinstance(image, np.ndarray): # If it's a NumPy array from Gradio
116
+ image = Image.fromarray(image) # Convert to PIL Image
117
+
118
+ print("🖼️ Generating caption for image...")
119
+ caption = image_captioning_pipeline(image)[0]['generated_text']
120
+
121
+ print("🤖 Answering question based on caption...")
122
+ response = doc_qa_pipeline(f"Question: {question}\nContext: {caption}")
123
+
124
+ return response[0]["generated_text"]
125
+
126
+ except Exception as e:
127
+ return f"❌ Error processing image: {str(e)}"
128
+
129
 
130
  # Gradio UI for Document & Image QA
131
  doc_interface = gr.Interface(