-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
87 lines (65 loc) Β· 2.07 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
import torch
import json
import asyncio
from pydantic import BaseModel
from fastapi import FastAPI, Query, Request, Body
from routers import websocket
from starlette.responses import FileResponse
from fastapi.staticfiles import StaticFiles
from fastapi.middleware.cors import CORSMiddleware
from routers import langchain
from typing import List
app = FastAPI()
# Add CORS middleware
app.add_middleware(
CORSMiddleware,
# Should be edited in production env
allow_origins=["*"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
app.include_router(websocket.router)
app.mount("/images", StaticFiles(directory="images"), name="images")
@app.get("/")
def read_root():
return FileResponse("./templates/index.html")
@app.get("/sttModification")
async def sttModification(text: str = Query(..., description="The text to be modified")):
print("[main]-[sttModification] API Call :", text)
while(True):
llm_result = await asyncio.create_task(langchain.speech_to_text_modification(
"connection_uuid",
text
))
if(llm_result != None):
return llm_result
class scriptReq(BaseModel):
processedScript: List[str]
@app.post("/restructure_script")
async def restructure_script(script_Req : scriptReq):
print("[main]-[restructure_script] API Call")
restructure_result = await asyncio.create_task(langchain.restructure_script(
script_Req.processedScript
))
return restructure_result
class problemReq(BaseModel):
script: str
subject : str
problem_num : int
problem_types : str
@app.post("/generateProblems")
async def generate_problems(problem_req: problemReq):
print("[main]-[generate_problems] API Call")
data = problem_req
script = data.script
subject = data.subject
problem_num = data.problem_num
problem_types = data.problem_types
generate_result = await asyncio.create_task(langchain.generate_problems_full(
script,
subject,
problem_num,
problem_types
))
return generate_result