Shahriar-jaman commited on
Commit
4c3b1d9
·
verified ·
1 Parent(s): 1485ba7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -6
app.py CHANGED
@@ -31,17 +31,17 @@ async def predict(files: List[UploadFile] = File(...)):
31
  image = Image.open(io.BytesIO(image_data)).convert("RGB")
32
 
33
  # Generate description
34
- inputs = processor(text=["Describe the image in detail."], images=[image], return_tensors="pt")
35
  outputs = model.generate(**inputs, max_length=100)
36
  description = processor.decode(outputs[0], skip_special_tokens=True).replace("Describe the image in detail.", "").strip()
37
 
38
  # Extract signs/number plates (OCR)
39
- inputs_ocr = processor(text=["Extract all text visible in the image."], images=[image], return_tensors="pt")
40
  ocr_outputs = model.generate(**inputs_ocr, max_length=100)
41
  signs_text = processor.decode(ocr_outputs[0], skip_special_tokens=True).replace("Extract all text visible in the image.", "").strip()
42
 
43
  # Detect harmful objects/blood
44
- inputs_detect = processor(text=["List all objects in the image."], images=[image], return_tensors="pt")
45
  detect_outputs = model.generate(**inputs_detect, max_length=100)
46
  detected_objects = processor.decode(detect_outputs[0], skip_special_tokens=True).lower()
47
  harmful_detected = any(obj in detected_objects for obj in harmful_objects) and "Detected: " + ", ".join([obj for obj in harmful_objects if obj in detected_objects]) or "None detected"
@@ -89,17 +89,17 @@ def gradio_predict(*images):
89
  image = Image.fromarray(image).convert("RGB")
90
 
91
  # Generate description
92
- inputs = processor(text=["Describe the image in detail."], images=[image], return_tensors="pt")
93
  outputs = model.generate(**inputs, max_length=100)
94
  description = processor.decode(outputs[0], skip_special_tokens=True).replace("Describe the image in detail.", "").strip()
95
 
96
  # Extract signs/number plates (OCR)
97
- inputs_ocr = processor(text=["Extract all text visible in the image."], images=[image], return_tensors="pt")
98
  ocr_outputs = model.generate(**inputs_ocr, max_length=100)
99
  signs_text = processor.decode(ocr_outputs[0], skip_special_tokens=True).replace("Extract all text visible in the image.", "").strip()
100
 
101
  # Detect harmful objects/blood
102
- inputs_detect = processor(text=["List all objects in the image."], images=[image], return_tensors="pt")
103
  detect_outputs = model.generate(**inputs_detect, max_length=100)
104
  detected_objects = processor.decode(detect_outputs[0], skip_special_tokens=True).lower()
105
  harmful_detected = any(obj in detected_objects for obj in harmful_objects) and "Detected: " + ", ".join([obj for obj in harmful_objects if obj in detected_objects]) or "None detected"
 
31
  image = Image.open(io.BytesIO(image_data)).convert("RGB")
32
 
33
  # Generate description
34
+ inputs = processor(text=["<image> Describe the image in detail."], images=[image], return_tensors="pt")
35
  outputs = model.generate(**inputs, max_length=100)
36
  description = processor.decode(outputs[0], skip_special_tokens=True).replace("Describe the image in detail.", "").strip()
37
 
38
  # Extract signs/number plates (OCR)
39
+ inputs_ocr = processor(text=["<image> Extract all text visible in the image."], images=[image], return_tensors="pt")
40
  ocr_outputs = model.generate(**inputs_ocr, max_length=100)
41
  signs_text = processor.decode(ocr_outputs[0], skip_special_tokens=True).replace("Extract all text visible in the image.", "").strip()
42
 
43
  # Detect harmful objects/blood
44
+ inputs_detect = processor(text=["<image> List all objects in the image."], images=[image], return_tensors="pt")
45
  detect_outputs = model.generate(**inputs_detect, max_length=100)
46
  detected_objects = processor.decode(detect_outputs[0], skip_special_tokens=True).lower()
47
  harmful_detected = any(obj in detected_objects for obj in harmful_objects) and "Detected: " + ", ".join([obj for obj in harmful_objects if obj in detected_objects]) or "None detected"
 
89
  image = Image.fromarray(image).convert("RGB")
90
 
91
  # Generate description
92
+ inputs = processor(text=["<image> Describe the image in detail."], images=[image], return_tensors="pt")
93
  outputs = model.generate(**inputs, max_length=100)
94
  description = processor.decode(outputs[0], skip_special_tokens=True).replace("Describe the image in detail.", "").strip()
95
 
96
  # Extract signs/number plates (OCR)
97
+ inputs_ocr = processor(text=["<image> Extract all text visible in the image."], images=[image], return_tensors="pt")
98
  ocr_outputs = model.generate(**inputs_ocr, max_length=100)
99
  signs_text = processor.decode(ocr_outputs[0], skip_special_tokens=True).replace("Extract all text visible in the image.", "").strip()
100
 
101
  # Detect harmful objects/blood
102
+ inputs_detect = processor(text=["<image> List all objects in the image."], images=[image], return_tensors="pt")
103
  detect_outputs = model.generate(**inputs_detect, max_length=100)
104
  detected_objects = processor.decode(detect_outputs[0], skip_special_tokens=True).lower()
105
  harmful_detected = any(obj in detected_objects for obj in harmful_objects) and "Detected: " + ", ".join([obj for obj in harmful_objects if obj in detected_objects]) or "None detected"