This repository has been archived by the owner on Aug 24, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
92 lines (63 loc) · 2.95 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
from fastapi import FastAPI
from fastapi.responses import StreamingResponse
from kernel.camera.manager import CameraManager
from kernel.provider import AuroraEchoConfig, AuroraEchoProvider
from fastapi.middleware.cors import CORSMiddleware
from pydantic import BaseModel
app = FastAPI()
app.add_middleware(CORSMiddleware, allow_origins=['*'], allow_credentials=True, allow_methods=['*'],
allow_headers=['*'])
camera = CameraManager()
config = AuroraEchoConfig(mosaic=True)
provider = AuroraEchoProvider(camera, config)
@app.get("/")
def read_root():
return {"app_name": "Aurora Echo"}
@app.get("/camera/{mosaic}")
async def camera_feed(mosaic: str = 'blur'):
return StreamingResponse(camera.video_frame(mosaic=mosaic), media_type='multipart/x-mixed-replace; boundary=frame')
@app.post('/record')
async def record():
provider.start_recognize()
@app.get('/text')
async def text():
return {'status': 'error', 'message': 'record is not completed'} if provider.recognizing else {'status': 'success',
'data': provider.text}
@app.get('/sentiment')
async def sentiment():
return {'status': 'error', 'message': 'record is not completed'} if provider.recognizing else {'status': 'success',
'data': provider.sentiment}
@app.get('/named_entities')
async def named_entities():
return {'status': 'error', 'message': 'record is not completed'} if provider.recognizing else {'status': 'success',
'data': provider.named_entities}
@app.post('/llm/{model}')
async def llm(model: str):
provider.start_llm('object', model)
provider.start_llm('subject', model)
provider.start_llm('json', model)
@app.get('/llm/object')
async def llm_object():
return {'status': 'error', 'message': 'generation is not completed'} if provider.generating else {
'status': 'success', 'data': provider.get_object_analysis()}
@app.get('/llm/subject')
async def llm_subject():
return {'status': 'error', 'message': 'generation is not completed'} if provider.generating else {
'status': 'success', 'data': provider.get_subject_analysis()}
class Product(BaseModel):
product: str
class Mosaic(BaseModel):
mosaic: bool
@app.post('/mosaic')
async def config_mosaic(mosaic: Mosaic):
provider.set_mosaic(mosaic.mosaic)
print(provider.apply_mosaic)
@app.get('/emotion')
async def get_emotion():
emotion = provider.camera.get_emotion_percents()
return emotion
@app.get('/thumb')
async def get_thumb():
thumbs = provider.camera.thumbs
total = thumbs['up'] + thumbs['down'] if thumbs['up'] + thumbs['down'] > 0 else 1
return [('thumb up', thumbs['up'] / total), ('thumb down', thumbs['down'] / total)].sort(key=lambda x: x[1], reverse=True)