Update TextGen/router.py
Browse files- TextGen/router.py +26 -1
TextGen/router.py
CHANGED
@@ -1,4 +1,5 @@
|
|
1 |
import os
|
|
|
2 |
from pydantic import BaseModel
|
3 |
from fastapi import FastAPI, HTTPException, Query
|
4 |
from fastapi.responses import FileResponse
|
@@ -6,6 +7,7 @@ from fastapi.middleware.cors import CORSMiddleware
|
|
6 |
|
7 |
from langchain.chains import LLMChain
|
8 |
from langchain.prompts import PromptTemplate
|
|
|
9 |
from langchain_google_genai import (
|
10 |
ChatGoogleGenerativeAI,
|
11 |
HarmBlockThreshold,
|
@@ -14,6 +16,7 @@ from langchain_google_genai import (
|
|
14 |
from TextGen import app
|
15 |
from gradio_client import Client
|
16 |
|
|
|
17 |
|
18 |
my_hf_token=os.environ["HF_TOKEN"]
|
19 |
|
@@ -87,4 +90,26 @@ async def generate_wav(text: str, language: str = "en"):
|
|
87 |
return FileResponse(wav_file_path, media_type="audio/wav", filename="output.wav")
|
88 |
|
89 |
except Exception as e:
|
90 |
-
raise HTTPException(status_code=500, detail=str(e))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import os
|
2 |
+
import time
|
3 |
from pydantic import BaseModel
|
4 |
from fastapi import FastAPI, HTTPException, Query
|
5 |
from fastapi.responses import FileResponse
|
|
|
7 |
|
8 |
from langchain.chains import LLMChain
|
9 |
from langchain.prompts import PromptTemplate
|
10 |
+
from suno import custom_generate_audio, get_audio_information
|
11 |
from langchain_google_genai import (
|
12 |
ChatGoogleGenerativeAI,
|
13 |
HarmBlockThreshold,
|
|
|
16 |
from TextGen import app
|
17 |
from gradio_client import Client
|
18 |
|
19 |
+
song_base_api=os.environ["VERCEL_API"]
|
20 |
|
21 |
my_hf_token=os.environ["HF_TOKEN"]
|
22 |
|
|
|
90 |
return FileResponse(wav_file_path, media_type="audio/wav", filename="output.wav")
|
91 |
|
92 |
except Exception as e:
|
93 |
+
raise HTTPException(status_code=500, detail=str(e))
|
94 |
+
|
95 |
+
@app.get("/generate_song")
|
96 |
+
async def generate_song(text: str):
|
97 |
+
try:
|
98 |
+
data = custom_generate_audio({
|
99 |
+
"prompt": f"{text}",
|
100 |
+
"make_instrumental": False,
|
101 |
+
"wait_audio": False
|
102 |
+
})
|
103 |
+
ids = f"{data[0]['id']},{data[1]['id']}"
|
104 |
+
print(f"ids: {ids}")
|
105 |
+
|
106 |
+
for _ in range(60):
|
107 |
+
data = get_audio_information(ids)
|
108 |
+
if data[0]["status"] == 'streaming':
|
109 |
+
print(f"{data[0]['id']} ==> {data[0]['audio_url']}")
|
110 |
+
print(f"{data[1]['id']} ==> {data[1]['audio_url']}")
|
111 |
+
break
|
112 |
+
# sleep 5s
|
113 |
+
time.sleep(5)
|
114 |
+
except:
|
115 |
+
print("Error")
|