Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -48,19 +48,19 @@ async def predict(files: List[UploadFile] = File(...)):
|
|
| 48 |
# Generate description
|
| 49 |
prompt_desc = "<image> Provide a detailed description of the image, including objects, colors, people, and environmental context."
|
| 50 |
inputs = processor(text=[prompt_desc], images=[image], return_tensors="pt", padding=True)
|
| 51 |
-
outputs = model.generate(**inputs,
|
| 52 |
description = processor.decode(outputs[0], skip_special_tokens=True).replace(prompt_desc, "").strip()
|
| 53 |
|
| 54 |
# Extract signs/number plates (OCR)
|
| 55 |
prompt_ocr = "<image> Extract all visible text in the image, such as road signs, license plates, or billboards, with exact wording."
|
| 56 |
inputs_ocr = processor(text=[prompt_ocr], images=[image], return_tensors="pt", padding=True)
|
| 57 |
-
ocr_outputs = model.generate(**inputs_ocr,
|
| 58 |
signs_text = processor.decode(ocr_outputs[0], skip_special_tokens=True).replace(prompt_ocr, "").strip()
|
| 59 |
|
| 60 |
# Detect harmful objects/blood with confidence simulation
|
| 61 |
prompt_detect = "<image> Identify any harmful objects (e.g., knife, gun, blood, syringe, bomb, blade) in the image. List them explicitly and estimate confidence (0-100%) for each detection based on clarity."
|
| 62 |
inputs_detect = processor(text=[prompt_detect], images=[image], return_tensors="pt", padding=True)
|
| 63 |
-
detect_outputs = model.generate(**inputs_detect,
|
| 64 |
detected_objects = processor.decode(detect_outputs[0], skip_special_tokens=True).lower()
|
| 65 |
harmful_detected = []
|
| 66 |
for obj in harmful_objects:
|
|
@@ -123,19 +123,19 @@ def gradio_predict(*images):
|
|
| 123 |
# Generate description
|
| 124 |
prompt_desc = "<image> Provide a detailed description of the image, including objects, colors, people, and environmental context."
|
| 125 |
inputs = processor(text=[prompt_desc], images=[image], return_tensors="pt", padding=True)
|
| 126 |
-
outputs = model.generate(**inputs,
|
| 127 |
description = processor.decode(outputs[0], skip_special_tokens=True).replace(prompt_desc, "").strip()
|
| 128 |
|
| 129 |
# Extract signs/number plates (OCR)
|
| 130 |
prompt_ocr = "<image> Extract all visible text in the image, such as road signs, license plates, or billboards, with exact wording."
|
| 131 |
inputs_ocr = processor(text=[prompt_ocr], images=[image], return_tensors="pt", padding=True)
|
| 132 |
-
ocr_outputs = model.generate(**inputs_ocr,
|
| 133 |
signs_text = processor.decode(ocr_outputs[0], skip_special_tokens=True).replace(prompt_ocr, "").strip()
|
| 134 |
|
| 135 |
# Detect harmful objects/blood with confidence simulation
|
| 136 |
prompt_detect = "<image> Identify any harmful objects (e.g., knife, gun, blood, syringe, bomb, blade) in the image. List them explicitly and estimate confidence (0-100%) for each detection based on clarity."
|
| 137 |
inputs_detect = processor(text=[prompt_detect], images=[image], return_tensors="pt", padding=True)
|
| 138 |
-
detect_outputs = model.generate(**inputs_detect,
|
| 139 |
detected_objects = processor.decode(detect_outputs[0], skip_special_tokens=True).lower()
|
| 140 |
harmful_detected = []
|
| 141 |
for obj in harmful_objects:
|
|
|
|
| 48 |
# Generate description
|
| 49 |
prompt_desc = "<image> Provide a detailed description of the image, including objects, colors, people, and environmental context."
|
| 50 |
inputs = processor(text=[prompt_desc], images=[image], return_tensors="pt", padding=True)
|
| 51 |
+
outputs = model.generate(**inputs, max_new_tokens=256)
|
| 52 |
description = processor.decode(outputs[0], skip_special_tokens=True).replace(prompt_desc, "").strip()
|
| 53 |
|
| 54 |
# Extract signs/number plates (OCR)
|
| 55 |
prompt_ocr = "<image> Extract all visible text in the image, such as road signs, license plates, or billboards, with exact wording."
|
| 56 |
inputs_ocr = processor(text=[prompt_ocr], images=[image], return_tensors="pt", padding=True)
|
| 57 |
+
ocr_outputs = model.generate(**inputs_ocr, max_new_tokens=256)
|
| 58 |
signs_text = processor.decode(ocr_outputs[0], skip_special_tokens=True).replace(prompt_ocr, "").strip()
|
| 59 |
|
| 60 |
# Detect harmful objects/blood with confidence simulation
|
| 61 |
prompt_detect = "<image> Identify any harmful objects (e.g., knife, gun, blood, syringe, bomb, blade) in the image. List them explicitly and estimate confidence (0-100%) for each detection based on clarity."
|
| 62 |
inputs_detect = processor(text=[prompt_detect], images=[image], return_tensors="pt", padding=True)
|
| 63 |
+
detect_outputs = model.generate(**inputs_detect, max_new_tokens=256)
|
| 64 |
detected_objects = processor.decode(detect_outputs[0], skip_special_tokens=True).lower()
|
| 65 |
harmful_detected = []
|
| 66 |
for obj in harmful_objects:
|
|
|
|
| 123 |
# Generate description
|
| 124 |
prompt_desc = "<image> Provide a detailed description of the image, including objects, colors, people, and environmental context."
|
| 125 |
inputs = processor(text=[prompt_desc], images=[image], return_tensors="pt", padding=True)
|
| 126 |
+
outputs = model.generate(**inputs, max_new_tokens=256)
|
| 127 |
description = processor.decode(outputs[0], skip_special_tokens=True).replace(prompt_desc, "").strip()
|
| 128 |
|
| 129 |
# Extract signs/number plates (OCR)
|
| 130 |
prompt_ocr = "<image> Extract all visible text in the image, such as road signs, license plates, or billboards, with exact wording."
|
| 131 |
inputs_ocr = processor(text=[prompt_ocr], images=[image], return_tensors="pt", padding=True)
|
| 132 |
+
ocr_outputs = model.generate(**inputs_ocr, max_new_tokens=256)
|
| 133 |
signs_text = processor.decode(ocr_outputs[0], skip_special_tokens=True).replace(prompt_ocr, "").strip()
|
| 134 |
|
| 135 |
# Detect harmful objects/blood with confidence simulation
|
| 136 |
prompt_detect = "<image> Identify any harmful objects (e.g., knife, gun, blood, syringe, bomb, blade) in the image. List them explicitly and estimate confidence (0-100%) for each detection based on clarity."
|
| 137 |
inputs_detect = processor(text=[prompt_detect], images=[image], return_tensors="pt", padding=True)
|
| 138 |
+
detect_outputs = model.generate(**inputs_detect, max_new_tokens=256)
|
| 139 |
detected_objects = processor.decode(detect_outputs[0], skip_special_tokens=True).lower()
|
| 140 |
harmful_detected = []
|
| 141 |
for obj in harmful_objects:
|