Commit
·
f712aee
1
Parent(s):
15d32eb
sddsd
Browse files
app.py
CHANGED
|
@@ -6,6 +6,13 @@ qwen_model = gr.load("models/Qwen/Qwen2-VL-7B-Instruct")
|
|
| 6 |
def process_images(images, prompt):
|
| 7 |
"""
|
| 8 |
Process multiple images with the Qwen2-VL model
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
"""
|
| 10 |
if not images:
|
| 11 |
return "Please upload at least one image."
|
|
@@ -17,35 +24,15 @@ def process_images(images, prompt):
|
|
| 17 |
continue
|
| 18 |
|
| 19 |
try:
|
| 20 |
-
#
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
{
|
| 26 |
-
"type": "text",
|
| 27 |
-
"text": prompt
|
| 28 |
-
},
|
| 29 |
-
{
|
| 30 |
-
"type": "image_url",
|
| 31 |
-
"image_url": {
|
| 32 |
-
"url": image
|
| 33 |
-
}
|
| 34 |
-
}
|
| 35 |
-
]
|
| 36 |
-
}
|
| 37 |
-
]
|
| 38 |
-
|
| 39 |
-
# Generate response using the loaded model
|
| 40 |
-
response = qwen_model.chat.completions.create(
|
| 41 |
-
model="Qwen/Qwen2-VL-7B-Instruct",
|
| 42 |
-
messages=message,
|
| 43 |
-
max_tokens=512,
|
| 44 |
-
temperature=0.7
|
| 45 |
)
|
| 46 |
|
| 47 |
-
#
|
| 48 |
-
description = response
|
| 49 |
results.append(f"Image {i+1}: {description}")
|
| 50 |
|
| 51 |
except Exception as e:
|
|
@@ -154,4 +141,4 @@ with gr.Blocks(
|
|
| 154 |
|
| 155 |
# Launch the app
|
| 156 |
if __name__ == "__main__":
|
| 157 |
-
demo.launch()
|
|
|
|
| 6 |
def process_images(images, prompt):
|
| 7 |
"""
|
| 8 |
Process multiple images with the Qwen2-VL model
|
| 9 |
+
|
| 10 |
+
Args:
|
| 11 |
+
images: List of uploaded images
|
| 12 |
+
prompt: User-provided prompt
|
| 13 |
+
|
| 14 |
+
Returns:
|
| 15 |
+
List of generated descriptions
|
| 16 |
"""
|
| 17 |
if not images:
|
| 18 |
return "Please upload at least one image."
|
|
|
|
| 24 |
continue
|
| 25 |
|
| 26 |
try:
|
| 27 |
+
# For vision models, we pass the image and text directly
|
| 28 |
+
# The model expects the image and prompt as separate arguments
|
| 29 |
+
response = qwen_model(
|
| 30 |
+
prompt, # Text prompt
|
| 31 |
+
image # Image file
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
)
|
| 33 |
|
| 34 |
+
# The response should be the generated text
|
| 35 |
+
description = response
|
| 36 |
results.append(f"Image {i+1}: {description}")
|
| 37 |
|
| 38 |
except Exception as e:
|
|
|
|
| 141 |
|
| 142 |
# Launch the app
|
| 143 |
if __name__ == "__main__":
|
| 144 |
+
demo.launch()
|