Spaces:
Sleeping
Sleeping
from fastapi import FastAPI, UploadFile, File | |
from fastapi.responses import JSONResponse | |
import shutil | |
import os | |
import application | |
import functions | |
#fotograf ozellikleri | |
heightImg = 300*4 | |
widthImg = 210*4 | |
#pathImage = "denemeler/100luk_numarali.jpg" | |
questions=25 | |
choices=6 | |
a1 = functions.read_answers("answers/test1-1.txt") | |
a2 = functions.answers2numbers(a1) | |
a3 = functions.read_answers("answers/test1-2.txt") | |
a4 = functions.answers2numbers(a3) | |
a5 = functions.read_answers("answers/test1-3.txt") | |
a6 = functions.answers2numbers(a5) | |
a7 = functions.read_answers("answers/test1-4.txt") | |
a8 = functions.answers2numbers(a7) | |
app = FastAPI() | |
# Upload endpoint | |
async def upload_image(image: UploadFile = File(...)): | |
try: | |
# Upload received file to a directory | |
upload_dir = "uploads" | |
os.makedirs(upload_dir, exist_ok=True) | |
with open(os.path.join(upload_dir, image.filename), "wb") as buffer: | |
shutil.copyfileobj(image.file, buffer) | |
# Process the uploaded image (you can replace this with your processing function) | |
result = application.optic1(ans_txt1=a2, | |
ans_txt2=a4, | |
ans_txt3=a6, | |
ans_txt4=a8, | |
pathImage= os.path.join(upload_dir, image.filename), | |
) | |
print(os.path.join(upload_dir, image.filename)) | |
# Return result as JSON | |
return JSONResponse(content=result) | |
except Exception as e: | |
return JSONResponse(content={"error": str(e)}) | |
if __name__ == "__main__": | |
import uvicorn | |
uvicorn.run(app, host="0.0.0.0", port=8000) | |