Prathamesh1420 commited on
Commit
83af1dd
·
verified ·
1 Parent(s): 58a4fdb

Delete app.py

Browse files
Files changed (1) hide show
  1. app.py +0 -59
app.py DELETED
@@ -1,59 +0,0 @@
1
- import gradio as gr
2
- import json
3
- from pathlib import Path
4
- from fastapi import FastAPI
5
- from fastapi.responses import HTMLResponse
6
- from fastrtc import Stream
7
- from huggingface_hub import hf_hub_download
8
- from pydantic import BaseModel, Field
9
- import os
10
- import cv2
11
-
12
- from inference import YOLOv10
13
-
14
- cur_dir = Path(__file__).parent
15
-
16
- model_file = hf_hub_download(
17
- repo_id="onnx-community/yolov10n", filename="onnx/model.onnx"
18
- )
19
-
20
- model = YOLOv10(model_file)
21
-
22
- def detection(image, conf_threshold=0.3):
23
- image = cv2.resize(image, (model.input_width, model.input_height))
24
- new_image = model.detect_objects(image, conf_threshold)
25
- return cv2.resize(new_image, (500, 500))
26
-
27
- stream = Stream(
28
- handler=detection,
29
- modality="video",
30
- mode="send-receive",
31
- additional_inputs=[gr.Slider(minimum=0, maximum=1, step=0.01, value=0.3)],
32
- rtc_configuration=None,
33
- concurrency_limit=None,
34
- )
35
-
36
- app = FastAPI()
37
- stream.mount(app)
38
-
39
- @app.get("/")
40
- async def serve_index():
41
- html_content = open(cur_dir / "index.html").read()
42
- return HTMLResponse(content=html_content)
43
-
44
- class InputData(BaseModel):
45
- webrtc_id: str
46
- conf_threshold: float = Field(ge=0, le=1)
47
-
48
- @app.post("/input_hook")
49
- async def update_input(data: InputData):
50
- stream.set_input(data.webrtc_id, data.conf_threshold)
51
-
52
- if __name__ == "__main__":
53
- if (mode := os.getenv("MODE")) == "UI":
54
- stream.ui.launch(server_port=7860)
55
- elif mode == "PHONE":
56
- stream.fastphone(host="0.0.0.0", port=7860)
57
- else:
58
- import uvicorn
59
- uvicorn.run(app, host="0.0.0.0", port=7860)