Spaces:
Runtime error
Runtime error
Update backend/app.py
Browse files- backend/app.py +29 -29
backend/app.py
CHANGED
@@ -1,29 +1,29 @@
|
|
1 |
-
from fastapi import FastAPI, UploadFile
|
2 |
-
from fastapi.responses import FileResponse
|
3 |
-
from
|
4 |
-
from
|
5 |
-
from
|
6 |
-
import os
|
7 |
-
|
8 |
-
app = FastAPI()
|
9 |
-
|
10 |
-
@app.post("/transcribe/")
|
11 |
-
async def transcribe(file: UploadFile):
|
12 |
-
file_path = f"audio/{file.filename}"
|
13 |
-
with open(file_path, "wb") as audio:
|
14 |
-
audio.write(await file.read())
|
15 |
-
|
16 |
-
text = transcribe_audio(file_path)
|
17 |
-
os.remove(file_path) # Cleanup audio file
|
18 |
-
return {"transcription": text}
|
19 |
-
|
20 |
-
@app.post("/response/")
|
21 |
-
async def get_response(input_text: str):
|
22 |
-
llm_response = get_llm_response(input_text)
|
23 |
-
audio_path = generate_speech(llm_response)
|
24 |
-
return {"response": llm_response, "audio_url": audio_path}
|
25 |
-
|
26 |
-
@app.get("/audio/{file_name}")
|
27 |
-
async def serve_audio(file_name: str):
|
28 |
-
file_path = f"audio/{file_name}"
|
29 |
-
return FileResponse(file_path)
|
|
|
1 |
+
from fastapi import FastAPI, UploadFile
|
2 |
+
from fastapi.responses import FileResponse
|
3 |
+
from whisper_utils import transcribe_audio
|
4 |
+
from gtts_utils import generate_speech
|
5 |
+
from llm_utils import get_llm_response
|
6 |
+
import os
|
7 |
+
|
8 |
+
app = FastAPI()
|
9 |
+
|
10 |
+
@app.post("/transcribe/")
|
11 |
+
async def transcribe(file: UploadFile):
|
12 |
+
file_path = f"audio/{file.filename}"
|
13 |
+
with open(file_path, "wb") as audio:
|
14 |
+
audio.write(await file.read())
|
15 |
+
|
16 |
+
text = transcribe_audio(file_path)
|
17 |
+
os.remove(file_path) # Cleanup audio file
|
18 |
+
return {"transcription": text}
|
19 |
+
|
20 |
+
@app.post("/response/")
|
21 |
+
async def get_response(input_text: str):
|
22 |
+
llm_response = get_llm_response(input_text)
|
23 |
+
audio_path = generate_speech(llm_response)
|
24 |
+
return {"response": llm_response, "audio_url": audio_path}
|
25 |
+
|
26 |
+
@app.get("/audio/{file_name}")
|
27 |
+
async def serve_audio(file_name: str):
|
28 |
+
file_path = f"audio/{file_name}"
|
29 |
+
return FileResponse(file_path)
|