Spaces:
Running
Running
Update app.py
Browse files
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 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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(
|