Spaces:
Running
Running
Update fluxai.py
Browse files
fluxai.py
CHANGED
@@ -5,6 +5,7 @@ from fastapi import HTTPException
|
|
5 |
import io
|
6 |
import requests
|
7 |
import os
|
|
|
8 |
from dotenv import load_dotenv
|
9 |
from pydantic import BaseModel
|
10 |
from pymongo import MongoClient
|
@@ -100,6 +101,7 @@ async def fluxai_image(payload: FluxAI):
|
|
100 |
status="False",
|
101 |
randydev={"error": "Failed to generate an image"}
|
102 |
)
|
|
|
103 |
if payload.auto_enhancer:
|
104 |
with Image.open(io.BytesIO(image_bytes)) as image:
|
105 |
enhancer = ImageEnhance.Sharpness(image)
|
@@ -111,24 +113,23 @@ async def fluxai_image(payload: FluxAI):
|
|
111 |
enhanced_image_bytes = io.BytesIO()
|
112 |
image.save(enhanced_image_bytes, format="JPEG", quality=95)
|
113 |
enhanced_image_bytes.seek(0)
|
114 |
-
|
115 |
-
file_path = "test.jpg"
|
116 |
-
with open(file_path, "wb") as f:
|
117 |
-
f.write(enhanced_image_bytes.getvalue())
|
118 |
|
119 |
-
|
120 |
-
|
121 |
-
response_uploaded = requests.post(url, files=files).json()
|
122 |
-
get_url = response_uploaded.get("url")
|
123 |
example_test = "Explain how this picture looks like."
|
124 |
x = GeminiLatest(api_keys=GOOGLE_API_KEY)
|
125 |
-
response = x.get_response_image(example_test,
|
|
|
126 |
return SuccessResponse(
|
127 |
status="True",
|
128 |
-
randydev={"
|
129 |
)
|
130 |
else:
|
131 |
-
|
|
|
|
|
|
|
|
|
132 |
|
133 |
except Exception as e:
|
134 |
return SuccessResponse(
|
@@ -140,4 +141,4 @@ async def fluxai_image(payload: FluxAI):
|
|
140 |
return SuccessResponse(
|
141 |
status="False",
|
142 |
randydev={"error": f"Not enough tokens. Current tokens: {tokens}. Please support @xtdevs"}
|
143 |
-
)
|
|
|
5 |
import io
|
6 |
import requests
|
7 |
import os
|
8 |
+
import base64
|
9 |
from dotenv import load_dotenv
|
10 |
from pydantic import BaseModel
|
11 |
from pymongo import MongoClient
|
|
|
101 |
status="False",
|
102 |
randydev={"error": "Failed to generate an image"}
|
103 |
)
|
104 |
+
|
105 |
if payload.auto_enhancer:
|
106 |
with Image.open(io.BytesIO(image_bytes)) as image:
|
107 |
enhancer = ImageEnhance.Sharpness(image)
|
|
|
113 |
enhanced_image_bytes = io.BytesIO()
|
114 |
image.save(enhanced_image_bytes, format="JPEG", quality=95)
|
115 |
enhanced_image_bytes.seek(0)
|
|
|
|
|
|
|
|
|
116 |
|
117 |
+
encoded_string = base64.b64encode(enhanced_image_bytes.getvalue()).decode("utf-8")
|
118 |
+
|
|
|
|
|
119 |
example_test = "Explain how this picture looks like."
|
120 |
x = GeminiLatest(api_keys=GOOGLE_API_KEY)
|
121 |
+
response = x.get_response_image(example_test, enhanced_image_bytes)
|
122 |
+
|
123 |
return SuccessResponse(
|
124 |
status="True",
|
125 |
+
randydev={"image_data": encoded_string, "caption": response}
|
126 |
)
|
127 |
else:
|
128 |
+
encoded_string = base64.b64encode(image_bytes).decode("utf-8")
|
129 |
+
return SuccessResponse(
|
130 |
+
status="True",
|
131 |
+
randydev={"image_data": encoded_string}
|
132 |
+
)
|
133 |
|
134 |
except Exception as e:
|
135 |
return SuccessResponse(
|
|
|
141 |
return SuccessResponse(
|
142 |
status="False",
|
143 |
randydev={"error": f"Not enough tokens. Current tokens: {tokens}. Please support @xtdevs"}
|
144 |
+
)
|