space-sue commited on
Commit
1d3dd21
·
1 Parent(s): 76d3d08

updated for dependency errors

Browse files
Files changed (4) hide show
  1. app.py +14 -9
  2. pyproject.toml +2 -2
  3. requirements.txt +2 -1
  4. uv.lock +21 -1
app.py CHANGED
@@ -8,18 +8,22 @@ from datetime import datetime
8
  from ultralytics import YOLO
9
  from transformers import BlipProcessor, BlipForQuestionAnswering
10
  import torch
 
 
11
 
12
  """
13
  For more information on `huggingface_hub` Inference API support, please check the docs: https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference
14
  """
15
- client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
16
 
17
  # Load YOLO-World model
18
  model = YOLO('yolov8x-world.pt')
19
 
20
  # Load BLIP model for VQA
21
- processor = BlipProcessor.from_pretrained("Salesforce/blip-vqa-base")
22
- vqa_model = BlipForQuestionAnswering.from_pretrained("Salesforce/blip-vqa-base")
 
 
23
 
24
  def analyze_fire_scene(frame):
25
  # Run YOLO-World inference with custom prompts
@@ -55,9 +59,6 @@ def analyze_fire_scene(frame):
55
  return fire_detected, smoke_detected, fire_details
56
 
57
  def get_fire_analysis(frame, fire_details):
58
- # Prepare image for BLIP
59
- inputs = processor(frame, return_tensors="pt")
60
-
61
  # Generate questions about the fire
62
  questions = [
63
  "Is there a fire in this image?",
@@ -69,9 +70,13 @@ def get_fire_analysis(frame, fire_details):
69
 
70
  analysis = []
71
  for question in questions:
72
- # Process question with BLIP
73
- inputs["question"] = question
 
74
 
 
 
 
75
  # Generate answer
76
  with torch.no_grad():
77
  outputs = vqa_model.generate(
@@ -84,7 +89,7 @@ def get_fire_analysis(frame, fire_details):
84
  length_penalty=1.0,
85
  temperature=1.0,
86
  )
87
- answer = processor.decode(outputs[0], skip_special_tokens=True)
88
  analysis.append(f"Q: {question}\nA: {answer}")
89
 
90
  return analysis
 
8
  from ultralytics import YOLO
9
  from transformers import BlipProcessor, BlipForQuestionAnswering
10
  import torch
11
+ import dotenv
12
+ dotenv.load_dotenv()
13
 
14
  """
15
  For more information on `huggingface_hub` Inference API support, please check the docs: https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference
16
  """
17
+ client = InferenceClient("HuggingFaceH4/zephyr-7b-beta",token=os.getenv("HUGGINGFACE_HUB_TOKEN"))
18
 
19
  # Load YOLO-World model
20
  model = YOLO('yolov8x-world.pt')
21
 
22
  # Load BLIP model for VQA
23
+ blip_processor = BlipProcessor.from_pretrained("Salesforce/blip-vqa-base", token=os.getenv("HUGGINGFACE_HUB_TOKEN"))
24
+ vqa_model = BlipForQuestionAnswering.from_pretrained("Salesforce/blip-vqa-base", token=os.getenv("HUGGINGFACE_HUB_TOKEN"))
25
+ device = "cuda" if torch.cuda.is_available() else "cpu"
26
+ vqa_model = vqa_model.to(device)
27
 
28
  def analyze_fire_scene(frame):
29
  # Run YOLO-World inference with custom prompts
 
59
  return fire_detected, smoke_detected, fire_details
60
 
61
  def get_fire_analysis(frame, fire_details):
 
 
 
62
  # Generate questions about the fire
63
  questions = [
64
  "Is there a fire in this image?",
 
70
 
71
  analysis = []
72
  for question in questions:
73
+ # Prepare image and question for BLIP
74
+ inputs = blip_processor(image=frame, question=question, return_tensors="pt")
75
+ inputs = inputs.to(device)
76
 
77
+ # out = vqa_model.generate(**inputs)
78
+ # print(blip_processor.decode(out[0], skip_special_tokens=True))
79
+
80
  # Generate answer
81
  with torch.no_grad():
82
  outputs = vqa_model.generate(
 
89
  length_penalty=1.0,
90
  temperature=1.0,
91
  )
92
+ answer = blip_processor.decode(outputs[0], skip_special_tokens=True)
93
  analysis.append(f"Q: {question}\nA: {answer}")
94
 
95
  return analysis
pyproject.toml CHANGED
@@ -11,12 +11,12 @@ dependencies = [
11
  "mcp[cli]>=1.9.3",
12
  "opencv-python>=4.11.0.86",
13
  "pillow>=11.2.1",
14
- "torch>=2.7.1",
15
  "transformers>=4.52.4",
16
  "ultralytics>=8.0.0",
17
  "huggingface_hub>=0.25.2",
18
- "torch",
19
  "transformers",
20
  "opencv-python",
 
 
21
  ]
22
 
 
11
  "mcp[cli]>=1.9.3",
12
  "opencv-python>=4.11.0.86",
13
  "pillow>=11.2.1",
 
14
  "transformers>=4.52.4",
15
  "ultralytics>=8.0.0",
16
  "huggingface_hub>=0.25.2",
 
17
  "transformers",
18
  "opencv-python",
19
+ "torch>=2.7.1",
20
+ "accelerate>=1.10.0",
21
  ]
22
 
requirements.txt CHANGED
@@ -1,4 +1,5 @@
1
  huggingface_hub==0.25.2
2
  torch
3
  transformers
4
- opencv-python
 
 
1
  huggingface_hub==0.25.2
2
  torch
3
  transformers
4
+ opencv-python
5
+ ultralytics
uv.lock CHANGED
@@ -19,6 +19,25 @@ resolution-markers = [
19
  "(python_full_version >= '3.13' and platform_machine != 'aarch64' and platform_system == 'Linux' and sys_platform != 'win32') or (python_full_version >= '3.13' and platform_system != 'Darwin' and platform_system != 'Linux' and sys_platform != 'win32')",
20
  ]
21
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
22
  [[package]]
23
  name = "aiofiles"
24
  version = "24.1.0"
@@ -2246,6 +2265,7 @@ name = "wild-fire-tracker"
2246
  version = "0.1.0"
2247
  source = { virtual = "." }
2248
  dependencies = [
 
2249
  { name = "bs4", marker = "platform_machine == 'aarch64' or platform_system != 'Linux' or sys_platform != 'win32'" },
2250
  { name = "gradio", marker = "platform_machine == 'aarch64' or platform_system != 'Linux' or sys_platform != 'win32'" },
2251
  { name = "httpx", marker = "platform_machine == 'aarch64' or platform_system != 'Linux' or sys_platform != 'win32'" },
@@ -2260,6 +2280,7 @@ dependencies = [
2260
 
2261
  [package.metadata]
2262
  requires-dist = [
 
2263
  { name = "bs4", specifier = ">=0.0.2" },
2264
  { name = "gradio", specifier = ">=5.33.1" },
2265
  { name = "httpx", specifier = ">=0.28.1" },
@@ -2268,7 +2289,6 @@ requires-dist = [
2268
  { name = "opencv-python" },
2269
  { name = "opencv-python", specifier = ">=4.11.0.86" },
2270
  { name = "pillow", specifier = ">=11.2.1" },
2271
- { name = "torch" },
2272
  { name = "torch", specifier = ">=2.7.1" },
2273
  { name = "transformers" },
2274
  { name = "transformers", specifier = ">=4.52.4" },
 
19
  "(python_full_version >= '3.13' and platform_machine != 'aarch64' and platform_system == 'Linux' and sys_platform != 'win32') or (python_full_version >= '3.13' and platform_system != 'Darwin' and platform_system != 'Linux' and sys_platform != 'win32')",
20
  ]
21
 
22
+ [[package]]
23
+ name = "accelerate"
24
+ version = "1.10.0"
25
+ source = { registry = "https://pypi.org/simple" }
26
+ dependencies = [
27
+ { name = "huggingface-hub", marker = "platform_machine == 'aarch64' or platform_system != 'Linux' or sys_platform != 'win32'" },
28
+ { name = "numpy", version = "2.2.6", source = { registry = "https://pypi.org/simple" }, marker = "(python_full_version < '3.11' and platform_machine == 'aarch64') or (python_full_version < '3.11' and platform_system != 'Linux') or (python_full_version < '3.11' and sys_platform != 'win32')" },
29
+ { name = "numpy", version = "2.3.0", source = { registry = "https://pypi.org/simple" }, marker = "(python_full_version >= '3.11' and platform_machine == 'aarch64') or (python_full_version >= '3.11' and platform_system != 'Linux') or (python_full_version >= '3.11' and sys_platform != 'win32')" },
30
+ { name = "packaging", marker = "platform_machine == 'aarch64' or platform_system != 'Linux' or sys_platform != 'win32'" },
31
+ { name = "psutil", marker = "platform_machine == 'aarch64' or platform_system != 'Linux' or sys_platform != 'win32'" },
32
+ { name = "pyyaml", marker = "platform_machine == 'aarch64' or platform_system != 'Linux' or sys_platform != 'win32'" },
33
+ { name = "safetensors", marker = "platform_machine == 'aarch64' or platform_system != 'Linux' or sys_platform != 'win32'" },
34
+ { name = "torch", marker = "platform_machine == 'aarch64' or platform_system != 'Linux' or sys_platform != 'win32'" },
35
+ ]
36
+ sdist = { url = "https://files.pythonhosted.org/packages/f7/66/be171836d86dc5b8698b3a9bf4b9eb10cb53369729939f88bf650167588b/accelerate-1.10.0.tar.gz", hash = "sha256:8270568fda9036b5cccdc09703fef47872abccd56eb5f6d53b54ea5fb7581496", size = 392261 }
37
+ wheels = [
38
+ { url = "https://files.pythonhosted.org/packages/30/dd/0107f0aa179869ee9f47ef5a2686abd5e022fdc82af901d535e52fe91ce1/accelerate-1.10.0-py3-none-any.whl", hash = "sha256:260a72b560e100e839b517a331ec85ed495b3889d12886e79d1913071993c5a3", size = 374718 },
39
+ ]
40
+
41
  [[package]]
42
  name = "aiofiles"
43
  version = "24.1.0"
 
2265
  version = "0.1.0"
2266
  source = { virtual = "." }
2267
  dependencies = [
2268
+ { name = "accelerate", marker = "platform_machine == 'aarch64' or platform_system != 'Linux' or sys_platform != 'win32'" },
2269
  { name = "bs4", marker = "platform_machine == 'aarch64' or platform_system != 'Linux' or sys_platform != 'win32'" },
2270
  { name = "gradio", marker = "platform_machine == 'aarch64' or platform_system != 'Linux' or sys_platform != 'win32'" },
2271
  { name = "httpx", marker = "platform_machine == 'aarch64' or platform_system != 'Linux' or sys_platform != 'win32'" },
 
2280
 
2281
  [package.metadata]
2282
  requires-dist = [
2283
+ { name = "accelerate", specifier = ">=1.10.0" },
2284
  { name = "bs4", specifier = ">=0.0.2" },
2285
  { name = "gradio", specifier = ">=5.33.1" },
2286
  { name = "httpx", specifier = ">=0.28.1" },
 
2289
  { name = "opencv-python" },
2290
  { name = "opencv-python", specifier = ">=4.11.0.86" },
2291
  { name = "pillow", specifier = ">=11.2.1" },
 
2292
  { name = "torch", specifier = ">=2.7.1" },
2293
  { name = "transformers" },
2294
  { name = "transformers", specifier = ">=4.52.4" },