Spaces:
Running
Running
Upload main.py
Browse files
main.py
CHANGED
@@ -594,52 +594,26 @@ def bing_dalle(item: BingDalle, api_key: None = Depends(validate_api_key)):
|
|
594 |
except BaseException as e:
|
595 |
return SuccessResponse(status="False", randydev={"data": f"Error: {e}"})
|
596 |
|
|
|
|
|
|
|
|
|
597 |
@app.post("/ryuzaki/dalle3xl")
|
598 |
def dalle_3xl(
|
599 |
item: Dalle3XL,
|
600 |
api_key: None = Depends(validate_api_key)
|
601 |
):
|
602 |
-
API_URL = f"https://ufoptg-ufop-api.hf.space/dall-e-3/prompt={item.query}"
|
603 |
try:
|
604 |
-
|
605 |
-
response = requests.get(API_URL, headers=headers)
|
606 |
-
response.raise_for_status()
|
607 |
-
except requests.exceptions.RequestException:
|
608 |
-
raise HTTPException(
|
609 |
-
status_code=500,
|
610 |
-
detail=internal_error
|
611 |
-
)
|
612 |
-
|
613 |
-
try:
|
614 |
-
data_1 = response.json()[0]
|
615 |
-
data_2 = response.json()[1]
|
616 |
-
data_3 = response.json()[2]
|
617 |
-
data_4 = response.json()[3]
|
618 |
-
data_response = requests.get(data_1)
|
619 |
-
data_response_2 = requests.get(data_2)
|
620 |
-
data_response_3 = requests.get(data_3)
|
621 |
-
data_response_4 = requests.get(data_4)
|
622 |
-
encoded_string = base64.b64encode(data_response.content).decode("utf-8")
|
623 |
-
encoded_string_2 = base64.b64encode(data_response_2.content).decode("utf-8")
|
624 |
-
encoded_string_3 = base64.b64encode(data_response_3.content).decode("utf-8")
|
625 |
-
encoded_string_4 = base64.b64encode(data_response_4.content).decode("utf-8")
|
626 |
except Exception:
|
627 |
raise HTTPException(
|
628 |
status_code=500,
|
629 |
detail=contact_support
|
630 |
)
|
631 |
-
|
632 |
-
if encoded_string and encoded_string_2 and encoded_string_3 and encoded_string_4:
|
633 |
return SuccessResponse(
|
634 |
status="True",
|
635 |
-
randydev=
|
636 |
-
{
|
637 |
-
"data": encoded_string,
|
638 |
-
"data_2": encoded_string_2,
|
639 |
-
"data_3": encoded_string_3,
|
640 |
-
"data_4": encoded_string_4
|
641 |
-
}
|
642 |
-
)
|
643 |
else:
|
644 |
return SuccessResponse(status="False", randydev={"data": contact_support})
|
645 |
|
|
|
594 |
except BaseException as e:
|
595 |
return SuccessResponse(status="False", randydev={"data": f"Error: {e}"})
|
596 |
|
597 |
+
def get_image_urls(query):
|
598 |
+
response = requests.get("https://ufoptg-ufop-api.hf.space/dall-e-3/prompt=" + query, headers=headers).json()
|
599 |
+
return [response[f"S{i}-Image"] for i in range(1, 5)]
|
600 |
+
|
601 |
@app.post("/ryuzaki/dalle3xl")
|
602 |
def dalle_3xl(
|
603 |
item: Dalle3XL,
|
604 |
api_key: None = Depends(validate_api_key)
|
605 |
):
|
|
|
606 |
try:
|
607 |
+
x_image = get_image_urls(item.query)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
608 |
except Exception:
|
609 |
raise HTTPException(
|
610 |
status_code=500,
|
611 |
detail=contact_support
|
612 |
)
|
613 |
+
if x_image:
|
|
|
614 |
return SuccessResponse(
|
615 |
status="True",
|
616 |
+
randydev={"url": x_image})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
617 |
else:
|
618 |
return SuccessResponse(status="False", randydev={"data": contact_support})
|
619 |
|