Spaces:
Running
Running
Update fluxai.py
Browse files
fluxai.py
CHANGED
@@ -103,33 +103,30 @@ async def fluxai_image(payload: FluxAI):
|
|
103 |
)
|
104 |
|
105 |
if payload.auto_enhancer:
|
106 |
-
with Image.open(
|
107 |
enhancer = ImageEnhance.Sharpness(image)
|
108 |
image = enhancer.enhance(1.5)
|
109 |
enhancer = ImageEnhance.Contrast(image)
|
110 |
image = enhancer.enhance(1.2)
|
111 |
enhancer = ImageEnhance.Color(image)
|
112 |
image = enhancer.enhance(1.1)
|
113 |
-
|
|
|
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,
|
122 |
|
123 |
return SuccessResponse(
|
124 |
status="True",
|
125 |
randydev={"image_data": encoded_string, "caption": response}
|
126 |
)
|
|
|
127 |
else:
|
128 |
-
|
129 |
-
return SuccessResponse(
|
130 |
-
status="True",
|
131 |
-
randydev={"image_data": encoded_string}
|
132 |
-
)
|
133 |
|
134 |
except Exception as e:
|
135 |
return SuccessResponse(
|
@@ -141,4 +138,4 @@ async def fluxai_image(payload: FluxAI):
|
|
141 |
return SuccessResponse(
|
142 |
status="False",
|
143 |
randydev={"error": f"Not enough tokens. Current tokens: {tokens}. Please support @xtdevs"}
|
144 |
-
)
|
|
|
103 |
)
|
104 |
|
105 |
if payload.auto_enhancer:
|
106 |
+
with Image.open(BytesIO(image_bytes)) as image:
|
107 |
enhancer = ImageEnhance.Sharpness(image)
|
108 |
image = enhancer.enhance(1.5)
|
109 |
enhancer = ImageEnhance.Contrast(image)
|
110 |
image = enhancer.enhance(1.2)
|
111 |
enhancer = ImageEnhance.Color(image)
|
112 |
image = enhancer.enhance(1.1)
|
113 |
+
|
114 |
+
enhanced_image_bytes = BytesIO()
|
115 |
image.save(enhanced_image_bytes, format="JPEG", quality=95)
|
116 |
enhanced_image_bytes.seek(0)
|
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, encoded_string)
|
122 |
|
123 |
return SuccessResponse(
|
124 |
status="True",
|
125 |
randydev={"image_data": encoded_string, "caption": response}
|
126 |
)
|
127 |
+
|
128 |
else:
|
129 |
+
return StreamingResponse(BytesIO(image_bytes), media_type="image/jpeg")
|
|
|
|
|
|
|
|
|
130 |
|
131 |
except Exception as e:
|
132 |
return SuccessResponse(
|
|
|
138 |
return SuccessResponse(
|
139 |
status="False",
|
140 |
randydev={"error": f"Not enough tokens. Current tokens: {tokens}. Please support @xtdevs"}
|
141 |
+
)
|