Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -13,7 +13,7 @@ processor = AutoProcessor.from_pretrained("microsoft/kosmos-2-patch14-224")
|
|
| 13 |
#prompt = "{question}"
|
| 14 |
|
| 15 |
async def describe_image(image_path, question : str):
|
| 16 |
-
inputs =
|
| 17 |
|
| 18 |
await generated_ids = model.generate(
|
| 19 |
pixel_values=inputs["pixel_values"],
|
|
@@ -24,12 +24,12 @@ async def describe_image(image_path, question : str):
|
|
| 24 |
use_cache=True,
|
| 25 |
max_new_tokens=128,
|
| 26 |
)
|
| 27 |
-
generated_text =
|
| 28 |
|
| 29 |
# Specify `cleanup_and_extract=False` in order to see the raw model generation.
|
| 30 |
-
processed_text =
|
| 31 |
|
| 32 |
-
processed_text, entities =
|
| 33 |
|
| 34 |
return processed_text
|
| 35 |
|
|
|
|
| 13 |
#prompt = "{question}"
|
| 14 |
|
| 15 |
async def describe_image(image_path, question : str):
|
| 16 |
+
inputs = processor(text=question, images=image_path, return_tensors="pt")
|
| 17 |
|
| 18 |
await generated_ids = model.generate(
|
| 19 |
pixel_values=inputs["pixel_values"],
|
|
|
|
| 24 |
use_cache=True,
|
| 25 |
max_new_tokens=128,
|
| 26 |
)
|
| 27 |
+
generated_text = processor.batch_decode(generated_ids, skip_special_tokens=True)[0]
|
| 28 |
|
| 29 |
# Specify `cleanup_and_extract=False` in order to see the raw model generation.
|
| 30 |
+
processed_text = processor.post_process_generation(generated_text, cleanup_and_extract=False)
|
| 31 |
|
| 32 |
+
processed_text, entities = processor.post_process_generation(generated_text)
|
| 33 |
|
| 34 |
return processed_text
|
| 35 |
|