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
|
@@ -140,18 +141,23 @@ async def fluxai_image(payload: FluxAI):
|
|
140 |
enhanced_image_bytes = io.BytesIO()
|
141 |
image.save(enhanced_image_bytes, format="JPEG", quality=95)
|
142 |
enhanced_image_bytes.seek(0)
|
143 |
-
|
144 |
-
file_path =
|
145 |
-
os.makedirs(os.path.dirname(file_path), exist_ok=True)
|
146 |
with open(file_path, "wb") as f:
|
147 |
f.write(enhanced_image_bytes.getvalue())
|
148 |
-
|
149 |
-
|
150 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
151 |
example_test = "Explain how this picture looks like."
|
152 |
x = GeminiLatest(api_keys=GOOGLE_API_KEY)
|
153 |
response = x.get_response_image(example_test, file_path)
|
154 |
-
url = response_uploaded.json().get("url")
|
155 |
return SuccessResponse(
|
156 |
status="True",
|
157 |
randydev={"url": url, "caption": response}
|
|
|
5 |
import io
|
6 |
import requests
|
7 |
import os
|
8 |
+
import httpx
|
9 |
from dotenv import load_dotenv
|
10 |
from pydantic import BaseModel
|
11 |
from pymongo import MongoClient
|
|
|
141 |
enhanced_image_bytes = io.BytesIO()
|
142 |
image.save(enhanced_image_bytes, format="JPEG", quality=95)
|
143 |
enhanced_image_bytes.seek(0)
|
144 |
+
|
145 |
+
file_path = "test.jpg"
|
|
|
146 |
with open(file_path, "wb") as f:
|
147 |
f.write(enhanced_image_bytes.getvalue())
|
148 |
+
|
149 |
+
async def upload_file(file_path: str):
|
150 |
+
url = "https://randydev-ryuzaki-api.hf.space/uploadfile/"
|
151 |
+
async with httpx.AsyncClient() as client:
|
152 |
+
with open(file_path, "rb") as f:
|
153 |
+
response = await client.post(url, files={"file": f})
|
154 |
+
return response.json()
|
155 |
+
|
156 |
+
response_uploaded = await upload_file(file_path)
|
157 |
+
url = response_uploaded.get("url")
|
158 |
example_test = "Explain how this picture looks like."
|
159 |
x = GeminiLatest(api_keys=GOOGLE_API_KEY)
|
160 |
response = x.get_response_image(example_test, file_path)
|
|
|
161 |
return SuccessResponse(
|
162 |
status="True",
|
163 |
randydev={"url": url, "caption": response}
|