-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
1,597 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,4 +38,5 @@ yarn-error.log* | |
*.pem | ||
.DS_Store | ||
|
||
__pycache__ | ||
__pycache__ | ||
tmp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
|
||
Run with docker | ||
```sh | ||
docker build -t lerm0/core . --platform=linux/amd64 | ||
docker run -it -v /Users/LermoAI/apps/api/core-api:/app lerm0/core bash | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
from fastapi import APIRouter, HTTPException, Depends, Header, Request | ||
from fastapi.responses import StreamingResponse, FileResponse | ||
|
||
from app.engine import create_podcast_script, text_to_voice | ||
|
||
router = APIRouter() | ||
|
||
@router.post("/podcast") | ||
async def chat_with_model(request: Request): | ||
try: | ||
params = await request.json() | ||
prompt = params.get("prompt") | ||
content = params.get("content") | ||
text = create_podcast_script(content) | ||
|
||
prompt_array = prompt.split(", ")[:2] | ||
file_name = prompt_array[0] | ||
speaker = prompt_array[1] | ||
file_path_full = f"/tmp/voice/{file_name}.wav" | ||
|
||
text_to_voice(text, file_path_full, speaker) | ||
return FileResponse(path=file_path_full, media_type="audio/wav", filename=f"{file_name}.wav") | ||
except Exception as e: | ||
raise HTTPException(status_code=500, detail=str(e)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
from langchain_openai import ChatOpenAI | ||
from melo.api import TTS | ||
|
||
|
||
llm = None | ||
VOICE_ENGINE = None | ||
device = 'cpu' | ||
def init_engine(): | ||
global llm | ||
global VOICE_ENGINE | ||
if not llm: | ||
llm = ChatOpenAI(model="gpt4", temperature=0) | ||
if not VOICE_ENGINE: | ||
VOICE_ENGINE = TTS(language='EN', device=device) | ||
|
||
def create_podcast_script(content: str): | ||
prompt = """ | ||
Go deep into {content} and explain like human talk max 300 words. | ||
""" | ||
result = llm.invoke(prompt.format(content=content)) | ||
return result.content | ||
|
||
def text_to_voice(text: str, file_path: str, speaker: str): | ||
speed = 1 | ||
speaker_ids = VOICE_ENGINE.hps.data.spk2id | ||
VOICE_ENGINE.tts_to_file(text, speaker_ids[speaker], file_path, speed=speed) | ||
print("Voice Generated") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
fastapi==0.111.0 | ||
uvicorn==0.29.0 | ||
uvicorn==0.29.0 | ||
langchain==0.2.1 | ||
langchain_openai==0.1.7 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.