Spaces:
Running
Running
Upload main.py
Browse files
main.py
CHANGED
@@ -58,9 +58,6 @@ from fastapi import Request, Header
|
|
58 |
from fastapi import Body, Query
|
59 |
from fastapi.staticfiles import StaticFiles
|
60 |
from fastapi.templating import Jinja2Templates
|
61 |
-
from fastapi import FastAPI, File, UploadFile
|
62 |
-
from fastapi.responses import FileResponse, JSONResponse
|
63 |
-
import uuid
|
64 |
|
65 |
import g4f
|
66 |
from g4f.client import Client
|
@@ -129,44 +126,10 @@ collection = db["users"]
|
|
129 |
|
130 |
trans = SyncTranslator()
|
131 |
|
132 |
-
app = FastAPI(docs_url=
|
133 |
app.include_router(fluxai_router, prefix="/api/v1")
|
134 |
app.include_router(whisper_router, prefix="/api/v1")
|
135 |
|
136 |
-
|
137 |
-
UPLOAD_DIR = "./uploads"
|
138 |
-
|
139 |
-
@app.post("/uploadfile/")
|
140 |
-
async def upload_file(file: UploadFile = File(...)):
|
141 |
-
try:
|
142 |
-
ext = file.filename.split(".")[-1]
|
143 |
-
unique_filename = f"{uuid.uuid4().hex}.{ext}"
|
144 |
-
file_location = os.path.join(UPLOAD_DIR, unique_filename)
|
145 |
-
|
146 |
-
with open(file_location, "wb") as f:
|
147 |
-
f.write(await file.read())
|
148 |
-
|
149 |
-
return JSONResponse(
|
150 |
-
status_code=200,
|
151 |
-
content={"url": f"https://randydev-ryuzaki-api.hf.space/uploads/{unique_filename}"}
|
152 |
-
)
|
153 |
-
except Exception as e:
|
154 |
-
return JSONResponse(
|
155 |
-
status_code=500,
|
156 |
-
content={"error": str(e)}
|
157 |
-
)
|
158 |
-
|
159 |
-
@app.get("/uploads/{filename}")
|
160 |
-
async def serve_file(filename: str):
|
161 |
-
file_location = os.path.join(UPLOAD_DIR, filename)
|
162 |
-
if os.path.exists(file_location):
|
163 |
-
return FileResponse(file_location)
|
164 |
-
return JSONResponse(
|
165 |
-
status_code=404,
|
166 |
-
content={"error": "File not found"}
|
167 |
-
)
|
168 |
-
|
169 |
-
|
170 |
timeout = 100
|
171 |
|
172 |
contact_support = """
|
@@ -325,21 +288,21 @@ def new_profile_clone(
|
|
325 |
bio=None
|
326 |
):
|
327 |
update_doc = {
|
328 |
-
"
|
329 |
-
"
|
330 |
-
"
|
331 |
-
"
|
332 |
}
|
333 |
collection.update_one({"user_id": user_id}, {"$set": update_doc}, upsert=True)
|
334 |
|
335 |
def get_profile_clone(user_id):
|
336 |
user = collection.find_one({"user_id": user_id})
|
337 |
if user:
|
338 |
-
first_name = user.get("
|
339 |
-
last_name = user.get("
|
340 |
-
profile_id = user.get("
|
341 |
bio = user.get("bio_2")
|
342 |
-
return first_name, last_name, profile_id, bio
|
343 |
else:
|
344 |
return None
|
345 |
|
@@ -467,24 +430,16 @@ def get_profile_(
|
|
467 |
api_key: None = Depends(validate_api_key)
|
468 |
):
|
469 |
try:
|
470 |
-
|
471 |
-
if
|
472 |
-
last_name_str = ""
|
473 |
-
else:
|
474 |
-
last_name_str = last_name
|
475 |
-
if bio is None:
|
476 |
-
bio_str = ""
|
477 |
-
else:
|
478 |
-
bio_str = bio
|
479 |
-
if first_name and profile_id:
|
480 |
return SuccessResponse(
|
481 |
status="True",
|
482 |
randydev={
|
483 |
"user_id": item.user_id,
|
484 |
-
"first_name":
|
485 |
-
"last_name":
|
486 |
-
"profile_id":
|
487 |
-
"bio":
|
488 |
}
|
489 |
)
|
490 |
else:
|
|
|
58 |
from fastapi import Body, Query
|
59 |
from fastapi.staticfiles import StaticFiles
|
60 |
from fastapi.templating import Jinja2Templates
|
|
|
|
|
|
|
61 |
|
62 |
import g4f
|
63 |
from g4f.client import Client
|
|
|
126 |
|
127 |
trans = SyncTranslator()
|
128 |
|
129 |
+
app = FastAPI(docs_url=None, redoc_url="/")
|
130 |
app.include_router(fluxai_router, prefix="/api/v1")
|
131 |
app.include_router(whisper_router, prefix="/api/v1")
|
132 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
133 |
timeout = 100
|
134 |
|
135 |
contact_support = """
|
|
|
288 |
bio=None
|
289 |
):
|
290 |
update_doc = {
|
291 |
+
"first_name": first_name,
|
292 |
+
"last_name": last_name,
|
293 |
+
"profile_id": profile_id,
|
294 |
+
"bio": bio
|
295 |
}
|
296 |
collection.update_one({"user_id": user_id}, {"$set": update_doc}, upsert=True)
|
297 |
|
298 |
def get_profile_clone(user_id):
|
299 |
user = collection.find_one({"user_id": user_id})
|
300 |
if user:
|
301 |
+
first_name = user.get("first_name")
|
302 |
+
last_name = user.get("last_name")
|
303 |
+
profile_id = user.get("profile_id")
|
304 |
bio = user.get("bio_2")
|
305 |
+
return [first_name, last_name, profile_id, bio]
|
306 |
else:
|
307 |
return None
|
308 |
|
|
|
430 |
api_key: None = Depends(validate_api_key)
|
431 |
):
|
432 |
try:
|
433 |
+
response = get_profile_clone(item.user_id)
|
434 |
+
if response[0]:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
435 |
return SuccessResponse(
|
436 |
status="True",
|
437 |
randydev={
|
438 |
"user_id": item.user_id,
|
439 |
+
"first_name": response[0],
|
440 |
+
"last_name": response[1],
|
441 |
+
"profile_id": response[2],
|
442 |
+
"bio": response[3],
|
443 |
}
|
444 |
)
|
445 |
else:
|