Spaces:
Running
Running
Update main.py
Browse files
main.py
CHANGED
|
@@ -594,8 +594,7 @@ async def get_completion(payload: Payload, request: Request, authenticated: bool
|
|
| 594 |
@lru_cache(maxsize=256)
|
| 595 |
def cached_url(url: str):
|
| 596 |
return url
|
| 597 |
-
|
| 598 |
-
@app.get("/images/{prompt:path}")
|
| 599 |
async def create_image(
|
| 600 |
prompt: str,
|
| 601 |
request: Request,
|
|
@@ -604,13 +603,15 @@ async def create_image(
|
|
| 604 |
if not server_status:
|
| 605 |
raise HTTPException(status_code=503, detail="Server is under maintenance.")
|
| 606 |
|
| 607 |
-
|
| 608 |
-
|
| 609 |
base = "https://image.pollinations.ai/prompt/"
|
| 610 |
-
final_url = f"{base}{prompt}"
|
| 611 |
-
if query:
|
| 612 |
-
final_url += f"?{query}"
|
| 613 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 614 |
final_url = cached_url(final_url)
|
| 615 |
|
| 616 |
try:
|
|
@@ -629,7 +630,8 @@ async def create_image(
|
|
| 629 |
raise HTTPException(status_code=504, detail="Image generation timeout.")
|
| 630 |
|
| 631 |
except Exception as e:
|
| 632 |
-
raise HTTPException(status_code=500, detail=f"Unexpected error: {e}")
|
|
|
|
| 633 |
@app.get("/usage")
|
| 634 |
async def get_usage_json(days: int = 7):
|
| 635 |
return usage_tracker.get_usage_summary(days)
|
|
|
|
| 594 |
@lru_cache(maxsize=256)
|
| 595 |
def cached_url(url: str):
|
| 596 |
return url
|
| 597 |
+
@app.get("/images/{prompt:path}")
|
|
|
|
| 598 |
async def create_image(
|
| 599 |
prompt: str,
|
| 600 |
request: Request,
|
|
|
|
| 603 |
if not server_status:
|
| 604 |
raise HTTPException(status_code=503, detail="Server is under maintenance.")
|
| 605 |
|
| 606 |
+
# Build base URL safely
|
|
|
|
| 607 |
base = "https://image.pollinations.ai/prompt/"
|
| 608 |
+
final_url = f"{base}{prompt}?nologo=true"
|
|
|
|
|
|
|
| 609 |
|
| 610 |
+
# If user provided custom query params, append them
|
| 611 |
+
if request.url.query:
|
| 612 |
+
final_url += f"&{request.url.query}"
|
| 613 |
+
|
| 614 |
+
# Apply caching wrapper
|
| 615 |
final_url = cached_url(final_url)
|
| 616 |
|
| 617 |
try:
|
|
|
|
| 630 |
raise HTTPException(status_code=504, detail="Image generation timeout.")
|
| 631 |
|
| 632 |
except Exception as e:
|
| 633 |
+
raise HTTPException(status_code=500, detail=f"Unexpected error: {str(e)}")
|
| 634 |
+
|
| 635 |
@app.get("/usage")
|
| 636 |
async def get_usage_json(days: int = 7):
|
| 637 |
return usage_tracker.get_usage_summary(days)
|