vumichien commited on
Commit
3fae5f0
Β·
1 Parent(s): 520369d

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +8 -9
main.py CHANGED
@@ -12,10 +12,8 @@ from fastapi.responses import StreamingResponse
12
  from fastapi.middleware.gzip import GZipMiddleware
13
 
14
  from utils import tts, read_image_file, pil_to_base64, base64_to_pil, get_hist
15
- from typing import Optional
16
  from huggingface_hub import hf_hub_download
17
 
18
-
19
  from io import BytesIO
20
  import zipfile
21
 
@@ -23,13 +21,14 @@ model_path = hf_hub_download(repo_id="ultralyticsplus/yolov8s", filename='yolov8
23
  model = YOLO(model_path)
24
 
25
  CLASS = model.model.names
26
- defaul_bot_voice = "γŠγ―γ„γ‚ˆγ†γ”γ–γ„γΎγ™"
27
- area_thres = 0.3
28
  ZIP = False
29
 
30
  app = FastAPI()
31
  app.add_middleware(GZipMiddleware, minimum_size=1000)
32
 
 
33
  @app.get("/")
34
  def read_root():
35
  return {"Message": "Application startup complete"}
@@ -53,7 +52,7 @@ async def predict_api(
53
  results = model.predict(image, show=False)[0]
54
  masks, boxes = results.masks, results.boxes
55
  area_image = image.width * image.height
56
-
57
  # select and crop face image
58
  if boxes is not None:
59
  for xyxy, conf, cls in zip(boxes.xyxy, boxes.conf, boxes.cls):
@@ -76,13 +75,13 @@ async def predict_api(
76
  if out_img is not None:
77
  diff_value = dist.euclidean(get_hist(out_img), get_hist(last_seen))
78
  print("Hist time", time.time() - start_time)
79
-
80
- # return results
81
  start_time = time.time()
82
  print(f"Distance: {most_close}. Different value: {diff_value}")
83
- if most_close >= area_thres and diff_value >= 0.5:
84
  if ZIP:
85
- voice_bot_path = tts(defaul_bot_voice, language="ja")
86
  image_bot_path = pil_to_base64(out_img)
87
  print("Voice time", time.time() - start_time)
88
  io = BytesIO()
 
12
  from fastapi.middleware.gzip import GZipMiddleware
13
 
14
  from utils import tts, read_image_file, pil_to_base64, base64_to_pil, get_hist
 
15
  from huggingface_hub import hf_hub_download
16
 
 
17
  from io import BytesIO
18
  import zipfile
19
 
 
21
  model = YOLO(model_path)
22
 
23
  CLASS = model.model.names
24
+ default_bot_voice = "γŠγ―γ„γ‚ˆγ†γ”γ–γ„γΎγ™"
25
+ area_threshold = 0.3
26
  ZIP = False
27
 
28
  app = FastAPI()
29
  app.add_middleware(GZipMiddleware, minimum_size=1000)
30
 
31
+
32
  @app.get("/")
33
  def read_root():
34
  return {"Message": "Application startup complete"}
 
52
  results = model.predict(image, show=False)[0]
53
  masks, boxes = results.masks, results.boxes
54
  area_image = image.width * image.height
55
+
56
  # select and crop face image
57
  if boxes is not None:
58
  for xyxy, conf, cls in zip(boxes.xyxy, boxes.conf, boxes.cls):
 
75
  if out_img is not None:
76
  diff_value = dist.euclidean(get_hist(out_img), get_hist(last_seen))
77
  print("Hist time", time.time() - start_time)
78
+
79
+ # return results
80
  start_time = time.time()
81
  print(f"Distance: {most_close}. Different value: {diff_value}")
82
+ if most_close >= area_threshold and diff_value >= 0.5:
83
  if ZIP:
84
+ voice_bot_path = tts(default_bot_voice, language="ja")
85
  image_bot_path = pil_to_base64(out_img)
86
  print("Voice time", time.time() - start_time)
87
  io = BytesIO()