Spaces:
Running
Running
Update main.py
Browse files
main.py
CHANGED
@@ -50,15 +50,13 @@ from serpapi import GoogleSearch
|
|
50 |
|
51 |
from fastapi import FastAPI, UploadFile, File, Response
|
52 |
from fastapi.security import OAuth2PasswordBearer, OAuth2PasswordRequestForm
|
53 |
-
from fastapi import Depends
|
54 |
from fastapi.openapi.utils import get_openapi
|
55 |
-
from fastapi.responses import StreamingResponse
|
56 |
-
from fastapi import
|
57 |
-
from fastapi import FastAPI, Request, Header
|
58 |
from fastapi import Body, Query
|
59 |
from fastapi.staticfiles import StaticFiles
|
60 |
from fastapi.templating import Jinja2Templates
|
61 |
-
from fastapi.responses import FileResponse
|
62 |
|
63 |
from pymongo import MongoClient
|
64 |
|
@@ -124,7 +122,15 @@ contact_support = """
|
|
124 |
We are aware that AI is currently offline. This seems to be caused by the API
|
125 |
We are investigating and doing our best to get things back online as soon as possible. Thank you for your patience
|
126 |
|
127 |
-
Contact Support @xtdevs
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
128 |
"""
|
129 |
|
130 |
def get_all_api_keys():
|
@@ -548,7 +554,7 @@ def dalle_3xl(
|
|
548 |
except requests.exceptions.RequestException:
|
549 |
raise HTTPException(
|
550 |
status_code=500,
|
551 |
-
detail=
|
552 |
)
|
553 |
|
554 |
try:
|
@@ -556,7 +562,7 @@ def dalle_3xl(
|
|
556 |
except Exception:
|
557 |
raise HTTPException(
|
558 |
status_code=500,
|
559 |
-
detail=
|
560 |
)
|
561 |
|
562 |
if encoded_string:
|
@@ -578,14 +584,14 @@ def open_dalle(
|
|
578 |
except requests.exceptions.RequestException:
|
579 |
raise HTTPException(
|
580 |
status_code=500,
|
581 |
-
detail=
|
582 |
)
|
583 |
try:
|
584 |
encoded_string = base64.b64encode(response.content).decode("utf-8")
|
585 |
except Exception:
|
586 |
raise HTTPException(
|
587 |
status_code=500,
|
588 |
-
detail=
|
589 |
)
|
590 |
if encoded_string:
|
591 |
return SuccessResponse(status="True", randydev={"data": encoded_string})
|
@@ -614,7 +620,7 @@ def Picsart_Pro(
|
|
614 |
logger.error(f"Error in Picsart request: {e}")
|
615 |
raise HTTPException(
|
616 |
status_code=500,
|
617 |
-
detail=
|
618 |
)
|
619 |
|
620 |
try:
|
@@ -626,7 +632,7 @@ def Picsart_Pro(
|
|
626 |
logger.error(f"Error in Picsart image retrieval: {e}")
|
627 |
raise HTTPException(
|
628 |
status_code=500,
|
629 |
-
detail=
|
630 |
)
|
631 |
|
632 |
if encoded_string:
|
@@ -648,14 +654,14 @@ def Anime_Styled(
|
|
648 |
except requests.exceptions.RequestException:
|
649 |
raise HTTPException(
|
650 |
status_code=500,
|
651 |
-
detail=
|
652 |
)
|
653 |
try:
|
654 |
encoded_string = base64.b64encode(response.content).decode("utf-8")
|
655 |
except Exception:
|
656 |
raise HTTPException(
|
657 |
status_code=500,
|
658 |
-
detail=
|
659 |
)
|
660 |
if encoded_string:
|
661 |
return SuccessResponse(status="True", randydev={"data": encoded_string})
|
@@ -672,14 +678,14 @@ def image_unsplash(item: GetImageUnsplash):
|
|
672 |
except requests.exceptions.RequestException:
|
673 |
raise HTTPException(
|
674 |
status_code=500,
|
675 |
-
detail=
|
676 |
)
|
677 |
try:
|
678 |
encoded_string = base64.b64encode(response.content).decode("utf-8")
|
679 |
except Exception:
|
680 |
raise HTTPException(
|
681 |
status_code=500,
|
682 |
-
detail=
|
683 |
)
|
684 |
if encoded_string:
|
685 |
return SuccessResponse(status="True", randydev={"data": encoded_string})
|
@@ -788,7 +794,7 @@ def v1beta3_google_ai(
|
|
788 |
message = results.get("output")
|
789 |
return SuccessResponse(status="True", randydev={"message": message})
|
790 |
except:
|
791 |
-
return SuccessResponse(status="False", randydev={"message":
|
792 |
|
793 |
@app.post("/ryuzaki/gemini-ai-pro", response_model=SuccessResponse, responses={422: {"model": ErrorStatus}})
|
794 |
def gemini_pro(item: GeminiPro):
|
@@ -862,7 +868,7 @@ def v1beta2_google_ai(
|
|
862 |
message = results.get("content")
|
863 |
return SuccessResponse(status="True", randydev={"message": message})
|
864 |
except:
|
865 |
-
return SuccessResponse(status="False", randydev={"message":
|
866 |
|
867 |
@app.post("/ryuzaki/new-monitor", response_model=SuccessResponse, responses={422: {"model": ErrorStatus}})
|
868 |
def new_monitor(
|
@@ -1369,6 +1375,17 @@ description = """
|
|
1369 |
|
1370 |
•Developed by [@xtdevs](https://t.me/xtdevs)
|
1371 |
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1372 |
def custom_openapi():
|
1373 |
if app.openapi_schema:
|
1374 |
return app.openapi_schema
|
@@ -1386,3 +1403,5 @@ def custom_openapi():
|
|
1386 |
return app.openapi_schema
|
1387 |
|
1388 |
app.openapi = custom_openapi
|
|
|
|
|
|
50 |
|
51 |
from fastapi import FastAPI, UploadFile, File, Response
|
52 |
from fastapi.security import OAuth2PasswordBearer, OAuth2PasswordRequestForm
|
53 |
+
from fastapi import Depends HTTPException, status
|
54 |
from fastapi.openapi.utils import get_openapi
|
55 |
+
from fastapi.responses import StreamingResponse, JSONResponse, FileResponse
|
56 |
+
from fastapi import Request, Header
|
|
|
57 |
from fastapi import Body, Query
|
58 |
from fastapi.staticfiles import StaticFiles
|
59 |
from fastapi.templating import Jinja2Templates
|
|
|
60 |
|
61 |
from pymongo import MongoClient
|
62 |
|
|
|
122 |
We are aware that AI is currently offline. This seems to be caused by the API
|
123 |
We are investigating and doing our best to get things back online as soon as possible. Thank you for your patience
|
124 |
|
125 |
+
~ Contact Support @xtdevs
|
126 |
+
"""
|
127 |
+
|
128 |
+
internal_error = """
|
129 |
+
There has been an Internal error. We are aware of this error and notice that it can be
|
130 |
+
caused by your search terms being to explict, too confusing, or it can be caused by the API.
|
131 |
+
Please modify your search terms and/or try again later thank you for your understanding.
|
132 |
+
|
133 |
+
~ @xtdevs Team
|
134 |
"""
|
135 |
|
136 |
def get_all_api_keys():
|
|
|
554 |
except requests.exceptions.RequestException:
|
555 |
raise HTTPException(
|
556 |
status_code=500,
|
557 |
+
detail=internal_error
|
558 |
)
|
559 |
|
560 |
try:
|
|
|
562 |
except Exception:
|
563 |
raise HTTPException(
|
564 |
status_code=500,
|
565 |
+
detail=contact_support
|
566 |
)
|
567 |
|
568 |
if encoded_string:
|
|
|
584 |
except requests.exceptions.RequestException:
|
585 |
raise HTTPException(
|
586 |
status_code=500,
|
587 |
+
detail=internal_error
|
588 |
)
|
589 |
try:
|
590 |
encoded_string = base64.b64encode(response.content).decode("utf-8")
|
591 |
except Exception:
|
592 |
raise HTTPException(
|
593 |
status_code=500,
|
594 |
+
detail=contact_support
|
595 |
)
|
596 |
if encoded_string:
|
597 |
return SuccessResponse(status="True", randydev={"data": encoded_string})
|
|
|
620 |
logger.error(f"Error in Picsart request: {e}")
|
621 |
raise HTTPException(
|
622 |
status_code=500,
|
623 |
+
detail=internal_error
|
624 |
)
|
625 |
|
626 |
try:
|
|
|
632 |
logger.error(f"Error in Picsart image retrieval: {e}")
|
633 |
raise HTTPException(
|
634 |
status_code=500,
|
635 |
+
detail=contact_support
|
636 |
)
|
637 |
|
638 |
if encoded_string:
|
|
|
654 |
except requests.exceptions.RequestException:
|
655 |
raise HTTPException(
|
656 |
status_code=500,
|
657 |
+
detail=internal_error
|
658 |
)
|
659 |
try:
|
660 |
encoded_string = base64.b64encode(response.content).decode("utf-8")
|
661 |
except Exception:
|
662 |
raise HTTPException(
|
663 |
status_code=500,
|
664 |
+
detail=contact_support
|
665 |
)
|
666 |
if encoded_string:
|
667 |
return SuccessResponse(status="True", randydev={"data": encoded_string})
|
|
|
678 |
except requests.exceptions.RequestException:
|
679 |
raise HTTPException(
|
680 |
status_code=500,
|
681 |
+
detail=internal_error
|
682 |
)
|
683 |
try:
|
684 |
encoded_string = base64.b64encode(response.content).decode("utf-8")
|
685 |
except Exception:
|
686 |
raise HTTPException(
|
687 |
status_code=500,
|
688 |
+
detail=contact_support
|
689 |
)
|
690 |
if encoded_string:
|
691 |
return SuccessResponse(status="True", randydev={"data": encoded_string})
|
|
|
794 |
message = results.get("output")
|
795 |
return SuccessResponse(status="True", randydev={"message": message})
|
796 |
except:
|
797 |
+
return SuccessResponse(status="False", randydev={"message": internal_error})
|
798 |
|
799 |
@app.post("/ryuzaki/gemini-ai-pro", response_model=SuccessResponse, responses={422: {"model": ErrorStatus}})
|
800 |
def gemini_pro(item: GeminiPro):
|
|
|
868 |
message = results.get("content")
|
869 |
return SuccessResponse(status="True", randydev={"message": message})
|
870 |
except:
|
871 |
+
return SuccessResponse(status="False", randydev={"message": internal_error})
|
872 |
|
873 |
@app.post("/ryuzaki/new-monitor", response_model=SuccessResponse, responses={422: {"model": ErrorStatus}})
|
874 |
def new_monitor(
|
|
|
1375 |
|
1376 |
•Developed by [@xtdevs](https://t.me/xtdevs)
|
1377 |
"""
|
1378 |
+
|
1379 |
+
def custom_exception_handler(request: Request, exc: HTTPException) -> JSONResponse:
|
1380 |
+
error_detail = [{"error": str(exc.detail)}]
|
1381 |
+
custom_error_model = CustomErrorResponseModel(detail=error_detail)
|
1382 |
+
|
1383 |
+
return JSONResponse(
|
1384 |
+
status_code=exc.status_code,
|
1385 |
+
content=custom_error_model.dict(),
|
1386 |
+
headers=exc.headers,
|
1387 |
+
)
|
1388 |
+
|
1389 |
def custom_openapi():
|
1390 |
if app.openapi_schema:
|
1391 |
return app.openapi_schema
|
|
|
1403 |
return app.openapi_schema
|
1404 |
|
1405 |
app.openapi = custom_openapi
|
1406 |
+
|
1407 |
+
app.add_exception_handler(HTTPException, custom_exception_handler)
|