Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -22,7 +22,7 @@ app.add_middleware(
|
|
| 22 |
|
| 23 |
OLLAMA_LIBRARY_URL = "https://ollama.com/library"
|
| 24 |
|
| 25 |
-
RATE_LIMIT =
|
| 26 |
WINDOW_SECONDS = 60 * 60 * 24
|
| 27 |
ip_store = {} # { ip: { "count": int, "reset": timestamp } }
|
| 28 |
AUDIO_RATE_LIMIT = 10
|
|
@@ -571,6 +571,36 @@ async def gensfx(request: Request, prompt: str = None):
|
|
| 571 |
async with httpx.AsyncClient(timeout=None) as client:
|
| 572 |
response = await client.get(url)
|
| 573 |
body_text = ""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 574 |
try:
|
| 575 |
body_text = response.text
|
| 576 |
except Exception:
|
|
@@ -594,7 +624,7 @@ async def gensfx(request: Request, prompt: str = None):
|
|
| 594 |
@app.post("/gen/video")
|
| 595 |
async def genvideo(request: Request, prompt: str = None):
|
| 596 |
client_ip = request.client.host
|
| 597 |
-
|
| 598 |
|
| 599 |
if prompt is None:
|
| 600 |
body = await request.json()
|
|
|
|
| 22 |
|
| 23 |
OLLAMA_LIBRARY_URL = "https://ollama.com/library"
|
| 24 |
|
| 25 |
+
RATE_LIMIT = 60
|
| 26 |
WINDOW_SECONDS = 60 * 60 * 24
|
| 27 |
ip_store = {} # { ip: { "count": int, "reset": timestamp } }
|
| 28 |
AUDIO_RATE_LIMIT = 10
|
|
|
|
| 571 |
async with httpx.AsyncClient(timeout=None) as client:
|
| 572 |
response = await client.get(url)
|
| 573 |
body_text = ""
|
| 574 |
+
try:
|
| 575 |
+
body_text = response.text
|
| 576 |
+
except Exception:
|
| 577 |
+
pass
|
| 578 |
+
if response.status_code != 200:
|
| 579 |
+
return JSONResponse(
|
| 580 |
+
status_code=response.status_code,
|
| 581 |
+
content={
|
| 582 |
+
"success": False,
|
| 583 |
+
"error": "Upstream music/sfx generation failed",
|
| 584 |
+
"status_code": response.status_code,
|
| 585 |
+
"message": body_text[:1000]
|
| 586 |
+
}
|
| 587 |
+
)
|
| 588 |
+
return Response(
|
| 589 |
+
response.content,
|
| 590 |
+
media_type="audio/mpeg"
|
| 591 |
+
)
|
| 592 |
+
|
| 593 |
+
@app.get("/gen/tts/{prompt}")
|
| 594 |
+
@app.post("/gen/tts")
|
| 595 |
+
async def gensfx(request: Request, prompt: str = None):
|
| 596 |
+
client_ip = request.client.host
|
| 597 |
+
check_rate_limit(client_ip)
|
| 598 |
+
if prompt is None:
|
| 599 |
+
prompt = (await request.json()).get("prompt")
|
| 600 |
+
url = f"https://gen.pollinations.ai/audio/{prompt}?key={PKEY}"
|
| 601 |
+
async with httpx.AsyncClient(timeout=None) as client:
|
| 602 |
+
response = await client.get(url)
|
| 603 |
+
body_text = ""
|
| 604 |
try:
|
| 605 |
body_text = response.text
|
| 606 |
except Exception:
|
|
|
|
| 624 |
@app.post("/gen/video")
|
| 625 |
async def genvideo(request: Request, prompt: str = None):
|
| 626 |
client_ip = request.client.host
|
| 627 |
+
check_rate_limit(client_ip)
|
| 628 |
|
| 629 |
if prompt is None:
|
| 630 |
body = await request.json()
|