Spaces:
Running
Running
Upload main.py
Browse files
main.py
CHANGED
@@ -599,14 +599,9 @@ def dalle_3xl(
|
|
599 |
item: Dalle3XL,
|
600 |
api_key: None = Depends(validate_api_key)
|
601 |
):
|
602 |
-
API_URL =
|
603 |
try:
|
604 |
-
|
605 |
-
headers = {
|
606 |
-
"Authorization": f"Bearer {HUGGING_TOKEN}",
|
607 |
-
"Content-Type": "application/json",
|
608 |
-
}
|
609 |
-
response = requests.post(API_URL, headers=headers, json=payload, timeout=timeout)
|
610 |
response.raise_for_status()
|
611 |
except requests.exceptions.RequestException:
|
612 |
raise HTTPException(
|
@@ -615,15 +610,35 @@ def dalle_3xl(
|
|
615 |
)
|
616 |
|
617 |
try:
|
618 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
619 |
except Exception:
|
620 |
raise HTTPException(
|
621 |
status_code=500,
|
622 |
detail=contact_support
|
623 |
)
|
624 |
|
625 |
-
if encoded_string:
|
626 |
-
return SuccessResponse(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
627 |
else:
|
628 |
return SuccessResponse(status="False", randydev={"data": contact_support})
|
629 |
|
|
|
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 |
+
response = requests.get(API_URL, headers=headers)
|
|
|
|
|
|
|
|
|
|
|
605 |
response.raise_for_status()
|
606 |
except requests.exceptions.RequestException:
|
607 |
raise HTTPException(
|
|
|
610 |
)
|
611 |
|
612 |
try:
|
613 |
+
data_1 = response.json()[0]
|
614 |
+
data_2 = response.json()[1]
|
615 |
+
data_3 = response.json()[2]
|
616 |
+
data_4 = response.json()[3]
|
617 |
+
data_response = requests.get(data_1)
|
618 |
+
data_response_2 = requests.get(data_2)
|
619 |
+
data_response_3 = requests.get(data_3)
|
620 |
+
data_response_4 = requests.get(data_4)
|
621 |
+
encoded_string = base64.b64encode(data_response.content).decode("utf-8")
|
622 |
+
encoded_string_2 = base64.b64encode(data_response_2.content).decode("utf-8")
|
623 |
+
encoded_string_3 = base64.b64encode(data_response_3.content).decode("utf-8")
|
624 |
+
encoded_string_4 = base64.b64encode(data_response_4.content).decode("utf-8")
|
625 |
except Exception:
|
626 |
raise HTTPException(
|
627 |
status_code=500,
|
628 |
detail=contact_support
|
629 |
)
|
630 |
|
631 |
+
if encoded_string and encoded_string_2 and encoded_string_3 and encoded_string_4:
|
632 |
+
return SuccessResponse(
|
633 |
+
status="True",
|
634 |
+
randydev=
|
635 |
+
{
|
636 |
+
"data": encoded_string,
|
637 |
+
"data_2": encoded_string_2,
|
638 |
+
"data_3": encoded_string_3,
|
639 |
+
"data_4": encoded_string_4
|
640 |
+
}
|
641 |
+
)
|
642 |
else:
|
643 |
return SuccessResponse(status="False", randydev={"data": contact_support})
|
644 |
|