Spaces:
Running
Running
Upload 2 files
Browse files
main.py
CHANGED
@@ -78,7 +78,8 @@ import logging
|
|
78 |
import functions as code
|
79 |
|
80 |
logging.basicConfig(level=logging.ERROR)
|
81 |
-
|
|
|
82 |
|
83 |
load_dotenv()
|
84 |
|
@@ -98,6 +99,7 @@ SOURCE_WHAT_GAY_URL = os.environ["SOURCE_WHAT_GAY_URL"]
|
|
98 |
SOURCE_ASSISTANT_GOOGLE_AI = os.environ["SOURCE_ASSISTANT_GOOGLE_AI"]
|
99 |
SOURCE_MONITOR_URL = os.environ["SOURCE_MONITOR_URL"]
|
100 |
SOURCE_OPENAI_ACCESS_URL = os.environ["SOURCE_OPENAI_ACCESS_URL"]
|
|
|
101 |
|
102 |
# api keys
|
103 |
REVERSE_IMAGE_API = os.environ["REVERSE_IMAGE_API"]
|
@@ -107,6 +109,7 @@ HUGGING_TOKEN = os.environ["HUGGING_TOKEN"]
|
|
107 |
ASSISTANT_GOOGLE_API_KEYS = os.environ["ASSISTANT_GOOGLE_API_KEYS"]
|
108 |
COOKIE_BARD_TOKEN = os.environ["COOKIE_BARD_TOKEN"]
|
109 |
MONITOR_API_KEYS = os.environ["MONITOR_API_KEYS"]
|
|
|
110 |
|
111 |
client_mongo = MongoClient(MONGO_URL)
|
112 |
db = client_mongo["tiktokbot"]
|
@@ -405,7 +408,7 @@ def get_translate(
|
|
405 |
)
|
406 |
except:
|
407 |
return SuccessResponse(
|
408 |
-
status="
|
409 |
randydev={"message": "Error not responding"})
|
410 |
|
411 |
@app.get("/ryuzaki/reverse", response_model=SuccessResponse, responses={422: {"model": ErrorStatus}})
|
@@ -547,6 +550,48 @@ def open_dalle(
|
|
547 |
else:
|
548 |
return SuccessResponse(status="False", randydev={"data": "Not found image data"})
|
549 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
550 |
@app.post("/ryuzaki/anime-styled")
|
551 |
def Anime_Styled(
|
552 |
item: AnimeStyled,
|
|
|
78 |
import functions as code
|
79 |
|
80 |
logging.basicConfig(level=logging.ERROR)
|
81 |
+
logging.basicConfig(level=logging.INFO)
|
82 |
+
logger = logging.getLogger(__name__)
|
83 |
|
84 |
load_dotenv()
|
85 |
|
|
|
99 |
SOURCE_ASSISTANT_GOOGLE_AI = os.environ["SOURCE_ASSISTANT_GOOGLE_AI"]
|
100 |
SOURCE_MONITOR_URL = os.environ["SOURCE_MONITOR_URL"]
|
101 |
SOURCE_OPENAI_ACCESS_URL = os.environ["SOURCE_OPENAI_ACCESS_URL"]
|
102 |
+
SOURCE_PICSART_URL = os.environ["SOURCE_PICSART_URL"]
|
103 |
|
104 |
# api keys
|
105 |
REVERSE_IMAGE_API = os.environ["REVERSE_IMAGE_API"]
|
|
|
109 |
ASSISTANT_GOOGLE_API_KEYS = os.environ["ASSISTANT_GOOGLE_API_KEYS"]
|
110 |
COOKIE_BARD_TOKEN = os.environ["COOKIE_BARD_TOKEN"]
|
111 |
MONITOR_API_KEYS = os.environ["MONITOR_API_KEYS"]
|
112 |
+
PICSART_API_KEY = os.environ["PICSART_API_KEY"]
|
113 |
|
114 |
client_mongo = MongoClient(MONGO_URL)
|
115 |
db = client_mongo["tiktokbot"]
|
|
|
408 |
)
|
409 |
except:
|
410 |
return SuccessResponse(
|
411 |
+
status="False",
|
412 |
randydev={"message": "Error not responding"})
|
413 |
|
414 |
@app.get("/ryuzaki/reverse", response_model=SuccessResponse, responses={422: {"model": ErrorStatus}})
|
|
|
550 |
else:
|
551 |
return SuccessResponse(status="False", randydev={"data": "Not found image data"})
|
552 |
|
553 |
+
@app.post("/ryuzaki/picsart-pro")
|
554 |
+
def Picsart_Pro(
|
555 |
+
item: Picsart,
|
556 |
+
api_key: None = Depends(validate_api_key)
|
557 |
+
):
|
558 |
+
API_URL = SOURCE_PICSART_URL
|
559 |
+
try:
|
560 |
+
if not os.path.exists(item.image_path):
|
561 |
+
raise HTTPException(status_code=400, detail="Image file not found")
|
562 |
+
|
563 |
+
files = {"image": ("brosur.png", open(item.image_path, "rb"), "image/png")}
|
564 |
+
payload = {"format": "PNG", "output_type": "cutout"}
|
565 |
+
headers = {"accept": "application/json", "x-picsart-api-key": PICSART_API_KEY}
|
566 |
+
|
567 |
+
with requests.post(url, headers=headers, data=payload, files=files) as response:
|
568 |
+
response.raise_for_status()
|
569 |
+
response_data = response.json()
|
570 |
+
urls = response_data["data"]["url"]
|
571 |
+
except requests.exceptions.RequestException as e:
|
572 |
+
logger.error(f"Error in Picsart request: {e}")
|
573 |
+
raise HTTPException(
|
574 |
+
status_code=500,
|
575 |
+
detail=CustomErrorResponseModel(detail=[{}])
|
576 |
+
)
|
577 |
+
|
578 |
+
try:
|
579 |
+
response_two = requests.get(urls)
|
580 |
+
response_two.raise_for_status()
|
581 |
+
|
582 |
+
encoded_string = base64.b64encode(response_two.content).decode("utf-8")
|
583 |
+
except requests.exceptions.RequestException as e:
|
584 |
+
logger.error(f"Error in Picsart image retrieval: {e}")
|
585 |
+
raise HTTPException(
|
586 |
+
status_code=500,
|
587 |
+
detail=CustomErrorResponseModel(detail=[{}])
|
588 |
+
)
|
589 |
+
|
590 |
+
if encoded_string:
|
591 |
+
return SuccessResponse(status="True", randydev={"data": encoded_string})
|
592 |
+
else:
|
593 |
+
return SuccessResponse(status="False", randydev={"data": "Not found image data"})
|
594 |
+
|
595 |
@app.post("/ryuzaki/anime-styled")
|
596 |
def Anime_Styled(
|
597 |
item: AnimeStyled,
|
models.py
CHANGED
@@ -147,3 +147,6 @@ class Chatgpt3Texts(BaseModel):
|
|
147 |
|
148 |
class TextCustom(BaseModel):
|
149 |
query: str
|
|
|
|
|
|
|
|
147 |
|
148 |
class TextCustom(BaseModel):
|
149 |
query: str
|
150 |
+
|
151 |
+
class Picsart(BaseModel):
|
152 |
+
image_path: str
|