Spaces:
Runtime error
Runtime error
using gradio instead of streamlit
Browse files
app.py
CHANGED
|
@@ -38,9 +38,15 @@ except Exception as e:
|
|
| 38 |
# Function to process the image and extract text
|
| 39 |
def process_image(image, keyword):
|
| 40 |
try:
|
|
|
|
|
|
|
|
|
|
| 41 |
# Use the image-to-text pipeline to extract text from the image
|
| 42 |
output_text_img_to_text = image_to_text_pipeline(image)
|
| 43 |
|
|
|
|
|
|
|
|
|
|
| 44 |
# Prepare input for Qwen model for image description
|
| 45 |
conversation = [{"role": "user", "content": [{"type": "image"}, {"type": "text", "text": "Describe this image."}]}]
|
| 46 |
text_prompt = processor_qwen.apply_chat_template(conversation, add_generation_prompt=True)
|
|
@@ -52,6 +58,9 @@ def process_image(image, keyword):
|
|
| 52 |
generated_ids_qwen = [output_ids_qwen[len(input_ids):] for input_ids, output_ids_qwen in zip(inputs_qwen.input_ids, output_ids_qwen)]
|
| 53 |
output_text_qwen = processor_qwen.batch_decode(generated_ids_qwen, skip_special_tokens=True, clean_up_tokenization_spaces=True)
|
| 54 |
|
|
|
|
|
|
|
|
|
|
| 55 |
extracted_text = output_text_img_to_text[0]['generated_text']
|
| 56 |
|
| 57 |
# Keyword search in the extracted text
|
|
|
|
| 38 |
# Function to process the image and extract text
|
| 39 |
def process_image(image, keyword):
|
| 40 |
try:
|
| 41 |
+
# Debugging: Check the type of the input image
|
| 42 |
+
print(f"Received image of type: {type(image)}")
|
| 43 |
+
|
| 44 |
# Use the image-to-text pipeline to extract text from the image
|
| 45 |
output_text_img_to_text = image_to_text_pipeline(image)
|
| 46 |
|
| 47 |
+
# Debugging: Check the output of the image-to-text model
|
| 48 |
+
print(f"Output from image-to-text pipeline: {output_text_img_to_text}")
|
| 49 |
+
|
| 50 |
# Prepare input for Qwen model for image description
|
| 51 |
conversation = [{"role": "user", "content": [{"type": "image"}, {"type": "text", "text": "Describe this image."}]}]
|
| 52 |
text_prompt = processor_qwen.apply_chat_template(conversation, add_generation_prompt=True)
|
|
|
|
| 58 |
generated_ids_qwen = [output_ids_qwen[len(input_ids):] for input_ids, output_ids_qwen in zip(inputs_qwen.input_ids, output_ids_qwen)]
|
| 59 |
output_text_qwen = processor_qwen.batch_decode(generated_ids_qwen, skip_special_tokens=True, clean_up_tokenization_spaces=True)
|
| 60 |
|
| 61 |
+
# Debugging: Check the output from the Qwen model
|
| 62 |
+
print(f"Output from Qwen model: {output_text_qwen}")
|
| 63 |
+
|
| 64 |
extracted_text = output_text_img_to_text[0]['generated_text']
|
| 65 |
|
| 66 |
# Keyword search in the extracted text
|