Spaces:
Running
Running
Update fluxai.py
Browse files
fluxai.py
CHANGED
@@ -77,13 +77,33 @@ def deduct_tokens_gpt(user_id, amount):
|
|
77 |
|
78 |
UPLOAD_DIRECTORY = "./uploads"
|
79 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
80 |
@router.get("/uploads/{filename}")
|
81 |
-
async def
|
82 |
-
|
83 |
-
if os.path.exists(
|
84 |
-
return FileResponse(
|
85 |
-
|
86 |
-
|
|
|
|
|
87 |
|
88 |
@router.post("/akeno/mistralai", response_model=SuccessResponse, responses={422: {"model": SuccessResponse}})
|
89 |
async def mistralai_(payload: MistralAI):
|
@@ -125,10 +145,13 @@ async def fluxai_image(payload: FluxAI):
|
|
125 |
os.makedirs(os.path.dirname(file_path), exist_ok=True)
|
126 |
with open(file_path, "wb") as f:
|
127 |
f.write(enhanced_image_bytes.getvalue())
|
|
|
|
|
|
|
128 |
example_test = "Explain how this picture looks like."
|
129 |
x = GeminiLatest(api_keys=GOOGLE_API_KEY)
|
130 |
response = x.get_response_image(example_test, file_path)
|
131 |
-
url =
|
132 |
return SuccessResponse(
|
133 |
status="True",
|
134 |
randydev={"url": url, "caption": response}
|
|
|
77 |
|
78 |
UPLOAD_DIRECTORY = "./uploads"
|
79 |
|
80 |
+
@router.post("/uploadfile/")
|
81 |
+
async def upload_file(file: UploadFile = File(...)):
|
82 |
+
try:
|
83 |
+
ext = file.filename.split(".")[-1]
|
84 |
+
unique_filename = f"{uuid.uuid4().hex}.{ext}"
|
85 |
+
file_location = os.path.join(UPLOAD_DIRECTORY, unique_filename)
|
86 |
+
with open(file_location, "wb") as f:
|
87 |
+
f.write(await file.read())
|
88 |
+
return JSONResponse(
|
89 |
+
status_code=200,
|
90 |
+
content={"url": f"https://randydev-ryuzaki-api.hf.space/uploads/{unique_filename}"}
|
91 |
+
)
|
92 |
+
except Exception as e:
|
93 |
+
return JSONResponse(
|
94 |
+
status_code=500,
|
95 |
+
content={"error": str(e)}
|
96 |
+
)
|
97 |
+
|
98 |
@router.get("/uploads/{filename}")
|
99 |
+
async def serve_file(filename: str):
|
100 |
+
file_location = os.path.join(UPLOAD_DIRECTORY, filename)
|
101 |
+
if os.path.exists(file_location):
|
102 |
+
return FileResponse(file_location)
|
103 |
+
return JSONResponse(
|
104 |
+
status_code=404,
|
105 |
+
content={"error": "File not found"}
|
106 |
+
)
|
107 |
|
108 |
@router.post("/akeno/mistralai", response_model=SuccessResponse, responses={422: {"model": SuccessResponse}})
|
109 |
async def mistralai_(payload: MistralAI):
|
|
|
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 |
+
url_request = "https://randydev-ryuzaki-api.hf.space/uploadfile/"
|
149 |
+
files = {"file": open(file_path, "rb")}
|
150 |
+
response_uploaded = requests.post(url, files=files)
|
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}
|