Spaces:
Running
Running
Upload 2 files
Browse files
main.py
CHANGED
@@ -70,12 +70,14 @@ from bardapi import Bard
|
|
70 |
|
71 |
from models import *
|
72 |
|
|
|
|
|
73 |
import logging
|
74 |
import functions as code
|
75 |
|
76 |
logging.basicConfig(level=logging.ERROR)
|
77 |
|
78 |
-
|
79 |
load_dotenv()
|
80 |
|
81 |
# Database url
|
@@ -86,6 +88,7 @@ SOURCE_UNSPLASH_URL = os.environ["SOURCE_UNSPLASH_URL"]
|
|
86 |
SOURCE_OCR_URL = os.environ["SOURCE_OCR_URL"]
|
87 |
SOURCE_ALPHA_URL = os.environ["SOURCE_ALPHA_URL"]
|
88 |
SOURCE_OPENDALLE_URL = os.environ["SOURCE_OPENDALLE_URL"]
|
|
|
89 |
SOURCE_WAIFU_URL = os.environ["SOURCE_WAIFU_URL"]
|
90 |
SOURCE_TIKTOK_WTF_URL = os.environ["SOURCE_TIKTOK_WTF_URL"]
|
91 |
SOURCE_TIKTOK_TECH_URL = os.environ["SOURCE_TIKTOK_TECH_URL"]
|
@@ -106,6 +109,8 @@ client_mongo = MongoClient(MONGO_URL)
|
|
106 |
db = client_mongo["tiktokbot"]
|
107 |
collection = db["users"]
|
108 |
|
|
|
|
|
109 |
app = FastAPI(docs_url=None, redoc_url="/")
|
110 |
|
111 |
def get_all_api_keys():
|
@@ -345,7 +350,7 @@ def sibyl_system(
|
|
345 |
api_key: None = Depends(validate_api_key)
|
346 |
):
|
347 |
sibyl_result = get_sibyl_system_banned(item.user_id)
|
348 |
-
if sibyl_result
|
349 |
sibyl_name, reason, is_banned, date_joined, sibyl_user_id = sibyl_result
|
350 |
return SuccessResponse(
|
351 |
status="True",
|
@@ -365,6 +370,25 @@ def sibyl_system(
|
|
365 |
}
|
366 |
)
|
367 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
368 |
@app.get("/ryuzaki/ai", response_model=SuccessResponse, responses={422: {"model": ErrorStatus}})
|
369 |
def ryuzaki_ai(
|
370 |
item: RyuzakiAi,
|
@@ -388,62 +412,6 @@ def ryuzaki_ai(
|
|
388 |
except Exception:
|
389 |
return {"status": "false", "message": "Internal server error"}
|
390 |
|
391 |
-
@app.post("/ryuzaki/opendalle")
|
392 |
-
async def open_dalle(
|
393 |
-
item: OpenDalle,
|
394 |
-
api_key: None = Depends(validate_api_key)
|
395 |
-
):
|
396 |
-
API_URL = SOURCE_OPENDALLE_URL
|
397 |
-
try:
|
398 |
-
payload = {"inputs": item.query}
|
399 |
-
headers = {"Authorization": f"Bearer {HUGGING_TOKEN}"}
|
400 |
-
response = requests.post(API_URL, headers=headers, json=payload)
|
401 |
-
response.raise_for_status()
|
402 |
-
except requests.exceptions.RequestException:
|
403 |
-
raise HTTPException(
|
404 |
-
status_code=500,
|
405 |
-
detail=CustomErrorResponseModel(detail=[{}])
|
406 |
-
)
|
407 |
-
try:
|
408 |
-
encoded_string = base64.b64encode(response.content).decode("utf-8")
|
409 |
-
except Exception:
|
410 |
-
raise HTTPException(
|
411 |
-
status_code=500,
|
412 |
-
detail=CustomErrorResponseModel(detail=[{}])
|
413 |
-
)
|
414 |
-
headers = {"Content-Type": "image/jpeg"}
|
415 |
-
return Response(
|
416 |
-
content=encoded_string,
|
417 |
-
media_type="image/jpeg",
|
418 |
-
headers=headers
|
419 |
-
)
|
420 |
-
|
421 |
-
@app.get("/ryuzaki/unsplash")
|
422 |
-
async def get_image_unsplash(item: GetImageUnsplash):
|
423 |
-
url = SOURCE_UNSPLASH_URL
|
424 |
-
image_url = f"{url}/?{item.query}/{item.size}"
|
425 |
-
try:
|
426 |
-
response = requests.get(image_url)
|
427 |
-
response.raise_for_status()
|
428 |
-
except requests.exceptions.RequestException:
|
429 |
-
raise HTTPException(
|
430 |
-
status_code=500,
|
431 |
-
detail=CustomErrorResponseModel(detail=[{}])
|
432 |
-
)
|
433 |
-
try:
|
434 |
-
encoded_string = base64.b64encode(response.content).decode("utf-8")
|
435 |
-
except Exception:
|
436 |
-
raise HTTPException(
|
437 |
-
status_code=500,
|
438 |
-
detail=CustomErrorResponseModel(detail=[{}])
|
439 |
-
)
|
440 |
-
headers = {"Content-Type": "image/jpeg"}
|
441 |
-
return Response(
|
442 |
-
content=encoded_string,
|
443 |
-
media_type="image/jpeg",
|
444 |
-
headers=headers
|
445 |
-
)
|
446 |
-
|
447 |
@app.get("/ryuzaki/reverse", response_model=SuccessResponse, responses={422: {"model": ErrorStatus}})
|
448 |
def google_reverse(
|
449 |
item: GoogleReverse,
|
@@ -506,6 +474,119 @@ def ocr_space_url(
|
|
506 |
except (json.JSONDecodeError, KeyError):
|
507 |
return "Error parsing the OCR response."
|
508 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
509 |
@app.post("/ryuzaki/chatgpt-model", response_model=SuccessResponse, responses={422: {"model": ErrorStatus}})
|
510 |
def chatgpt_model(item: ChatgptModel):
|
511 |
url = "https://lexica.qewertyy.me/models"
|
@@ -536,32 +617,6 @@ def chatgpt_model(item: ChatgptModel):
|
|
536 |
}
|
537 |
)
|
538 |
|
539 |
-
@app.get("/ryuzaki/freechatgpt-beta", response_model=SuccessResponse, responses={422: {"model": ErrorStatus}})
|
540 |
-
def free_chatgpt4_beta(item: ChatgptCustom):
|
541 |
-
try:
|
542 |
-
response = RendyDevChat(item.query).get_response_beta(joke=True)
|
543 |
-
return SuccessResponse(
|
544 |
-
status="True",
|
545 |
-
randydev={
|
546 |
-
"message": response
|
547 |
-
}
|
548 |
-
)
|
549 |
-
except:
|
550 |
-
return {"status": "false", "message": "Error response."}
|
551 |
-
|
552 |
-
@app.get("/ryuzaki/freechatgpt-bing", response_model=SuccessResponse, responses={422: {"model": ErrorStatus}})
|
553 |
-
def free_chatgpt4_bing(item: ChatgptCustom):
|
554 |
-
try:
|
555 |
-
response = RendyDevChat(query).get_response_bing(bing=True)
|
556 |
-
return SuccessResponse(
|
557 |
-
status="True",
|
558 |
-
randydev={
|
559 |
-
"message": response
|
560 |
-
}
|
561 |
-
)
|
562 |
-
except:
|
563 |
-
return {"status": "false", "message": "Error response."}
|
564 |
-
|
565 |
@app.post("/ryuzaki/google-ai", response_model=SuccessResponse, responses={422: {"model": ErrorStatus}})
|
566 |
def v1beta3_google_ai(
|
567 |
item: ChatgptCustom,
|
|
|
70 |
|
71 |
from models import *
|
72 |
|
73 |
+
from gpytranslate import SyncTranslator
|
74 |
+
|
75 |
import logging
|
76 |
import functions as code
|
77 |
|
78 |
logging.basicConfig(level=logging.ERROR)
|
79 |
|
80 |
+
|
81 |
load_dotenv()
|
82 |
|
83 |
# Database url
|
|
|
88 |
SOURCE_OCR_URL = os.environ["SOURCE_OCR_URL"]
|
89 |
SOURCE_ALPHA_URL = os.environ["SOURCE_ALPHA_URL"]
|
90 |
SOURCE_OPENDALLE_URL = os.environ["SOURCE_OPENDALLE_URL"]
|
91 |
+
SOURCE_ANIME_STYLED_URL = os.environ["SOURCE_ANIME_STYLED_URL"]
|
92 |
SOURCE_WAIFU_URL = os.environ["SOURCE_WAIFU_URL"]
|
93 |
SOURCE_TIKTOK_WTF_URL = os.environ["SOURCE_TIKTOK_WTF_URL"]
|
94 |
SOURCE_TIKTOK_TECH_URL = os.environ["SOURCE_TIKTOK_TECH_URL"]
|
|
|
109 |
db = client_mongo["tiktokbot"]
|
110 |
collection = db["users"]
|
111 |
|
112 |
+
trans = SyncTranslator()
|
113 |
+
|
114 |
app = FastAPI(docs_url=None, redoc_url="/")
|
115 |
|
116 |
def get_all_api_keys():
|
|
|
350 |
api_key: None = Depends(validate_api_key)
|
351 |
):
|
352 |
sibyl_result = get_sibyl_system_banned(item.user_id)
|
353 |
+
if sibyl_result:
|
354 |
sibyl_name, reason, is_banned, date_joined, sibyl_user_id = sibyl_result
|
355 |
return SuccessResponse(
|
356 |
status="True",
|
|
|
370 |
}
|
371 |
)
|
372 |
|
373 |
+
@app.get("/ryuzaki/translate", response_model=SuccessResponse, responses={422: {"model": ErrorStatus}})
|
374 |
+
def get_translate(
|
375 |
+
item: TranslateCustom,
|
376 |
+
):
|
377 |
+
try:
|
378 |
+
source = trans.detect(item.text)
|
379 |
+
translation = trans(item.text, sourcelang=source, targetlang=item.setlang)
|
380 |
+
return SuccessResponse(
|
381 |
+
status="True",
|
382 |
+
randydev={
|
383 |
+
"translation": translation.text,
|
384 |
+
"translation_original": item.text
|
385 |
+
}
|
386 |
+
)
|
387 |
+
except:
|
388 |
+
return SuccessResponse(
|
389 |
+
status="True",
|
390 |
+
randydev={"message": "Error not responding"})
|
391 |
+
|
392 |
@app.get("/ryuzaki/ai", response_model=SuccessResponse, responses={422: {"model": ErrorStatus}})
|
393 |
def ryuzaki_ai(
|
394 |
item: RyuzakiAi,
|
|
|
412 |
except Exception:
|
413 |
return {"status": "false", "message": "Internal server error"}
|
414 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
415 |
@app.get("/ryuzaki/reverse", response_model=SuccessResponse, responses={422: {"model": ErrorStatus}})
|
416 |
def google_reverse(
|
417 |
item: GoogleReverse,
|
|
|
474 |
except (json.JSONDecodeError, KeyError):
|
475 |
return "Error parsing the OCR response."
|
476 |
|
477 |
+
@app.get("/ryuzaki/freechatgpt-beta", response_model=SuccessResponse, responses={422: {"model": ErrorStatus}})
|
478 |
+
def free_chatgpt4_beta(item: ChatgptCustom):
|
479 |
+
try:
|
480 |
+
response = RendyDevChat(item.query).get_response_beta(joke=True)
|
481 |
+
return SuccessResponse(
|
482 |
+
status="True",
|
483 |
+
randydev={
|
484 |
+
"message": response
|
485 |
+
}
|
486 |
+
)
|
487 |
+
except:
|
488 |
+
return {"status": "false", "message": "Error response."}
|
489 |
+
|
490 |
+
@app.get("/ryuzaki/freechatgpt-bing", response_model=SuccessResponse, responses={422: {"model": ErrorStatus}})
|
491 |
+
def free_chatgpt4_bing(item: ChatgptCustom):
|
492 |
+
try:
|
493 |
+
response = RendyDevChat(query).get_response_bing(bing=True)
|
494 |
+
return SuccessResponse(
|
495 |
+
status="True",
|
496 |
+
randydev={
|
497 |
+
"message": response
|
498 |
+
}
|
499 |
+
)
|
500 |
+
except:
|
501 |
+
return {"status": "false", "message": "Error response."}
|
502 |
+
|
503 |
+
@app.post("/ryuzaki/opendalle")
|
504 |
+
def open_dalle(
|
505 |
+
item: OpenDalle,
|
506 |
+
api_key: None = Depends(validate_api_key)
|
507 |
+
):
|
508 |
+
API_URL = SOURCE_OPENDALLE_URL
|
509 |
+
try:
|
510 |
+
payload = {"inputs": item.query}
|
511 |
+
headers = {"Authorization": f"Bearer {HUGGING_TOKEN}"}
|
512 |
+
response = requests.post(API_URL, headers=headers, json=payload)
|
513 |
+
response.raise_for_status()
|
514 |
+
except requests.exceptions.RequestException:
|
515 |
+
raise HTTPException(
|
516 |
+
status_code=500,
|
517 |
+
detail=CustomErrorResponseModel(detail=[{}])
|
518 |
+
)
|
519 |
+
try:
|
520 |
+
encoded_string = base64.b64encode(response.content).decode("utf-8")
|
521 |
+
except Exception:
|
522 |
+
raise HTTPException(
|
523 |
+
status_code=500,
|
524 |
+
detail=CustomErrorResponseModel(detail=[{}])
|
525 |
+
)
|
526 |
+
headers = {"Content-Type": "image/jpeg"}
|
527 |
+
return Response(
|
528 |
+
content=encoded_string,
|
529 |
+
media_type="image/jpeg",
|
530 |
+
headers=headers
|
531 |
+
)
|
532 |
+
|
533 |
+
@app.post("/ryuzaki/anime-styled")
|
534 |
+
def Anime_Styled(
|
535 |
+
item: AnimeStyled,
|
536 |
+
api_key: None = Depends(validate_api_key)
|
537 |
+
):
|
538 |
+
API_URL = SOURCE_ANIME_STYLED_URL
|
539 |
+
try:
|
540 |
+
payload = {"inputs": item.query}
|
541 |
+
headers = {"Authorization": f"Bearer {HUGGING_TOKEN}"}
|
542 |
+
response = requests.post(API_URL, headers=headers, json=payload)
|
543 |
+
response.raise_for_status()
|
544 |
+
except requests.exceptions.RequestException:
|
545 |
+
raise HTTPException(
|
546 |
+
status_code=500,
|
547 |
+
detail=CustomErrorResponseModel(detail=[{}])
|
548 |
+
)
|
549 |
+
try:
|
550 |
+
encoded_string = base64.b64encode(response.content).decode("utf-8")
|
551 |
+
except Exception:
|
552 |
+
raise HTTPException(
|
553 |
+
status_code=500,
|
554 |
+
detail=CustomErrorResponseModel(detail=[{}])
|
555 |
+
)
|
556 |
+
headers = {"Content-Type": "image/jpeg"}
|
557 |
+
return Response(
|
558 |
+
content=encoded_string,
|
559 |
+
media_type="image/jpeg",
|
560 |
+
headers=headers
|
561 |
+
)
|
562 |
+
|
563 |
+
@app.post("/ryuzaki/unsplash")
|
564 |
+
def image_unsplash(item: GetImageUnsplash):
|
565 |
+
url = SOURCE_UNSPLASH_URL
|
566 |
+
image_url = f"{url}/?{item.query}/{item.size}"
|
567 |
+
try:
|
568 |
+
response = requests.get(image_url)
|
569 |
+
response.raise_for_status()
|
570 |
+
except requests.exceptions.RequestException:
|
571 |
+
raise HTTPException(
|
572 |
+
status_code=500,
|
573 |
+
detail=CustomErrorResponseModel(detail=[{}])
|
574 |
+
)
|
575 |
+
try:
|
576 |
+
encoded_string = base64.b64encode(response.content).decode("utf-8")
|
577 |
+
except Exception:
|
578 |
+
raise HTTPException(
|
579 |
+
status_code=500,
|
580 |
+
detail=CustomErrorResponseModel(detail=[{}])
|
581 |
+
)
|
582 |
+
headers = {"Content-Type": "image/jpeg"}
|
583 |
+
return Response(
|
584 |
+
content=encoded_string,
|
585 |
+
media_type="image/jpeg",
|
586 |
+
headers=headers
|
587 |
+
)
|
588 |
+
|
589 |
+
|
590 |
@app.post("/ryuzaki/chatgpt-model", response_model=SuccessResponse, responses={422: {"model": ErrorStatus}})
|
591 |
def chatgpt_model(item: ChatgptModel):
|
592 |
url = "https://lexica.qewertyy.me/models"
|
|
|
617 |
}
|
618 |
)
|
619 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
620 |
@app.post("/ryuzaki/google-ai", response_model=SuccessResponse, responses={422: {"model": ErrorStatus}})
|
621 |
def v1beta3_google_ai(
|
622 |
item: ChatgptCustom,
|
models.py
CHANGED
@@ -124,3 +124,10 @@ class DownloadLink(BaseModel):
|
|
124 |
|
125 |
class OpenDalle(BaseModel):
|
126 |
query: str
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
124 |
|
125 |
class OpenDalle(BaseModel):
|
126 |
query: str
|
127 |
+
|
128 |
+
class TranslateCustom(BaseModel):
|
129 |
+
text: str
|
130 |
+
setlang: str
|
131 |
+
|
132 |
+
class AnimeStyled(BaseModel):
|
133 |
+
query: str
|