Spaces:
				
			
			
	
			
			
		Sleeping
		
	
	
	
			
			
	
	
	
	
		
		
		Sleeping
		
	File size: 1,639 Bytes
			
			3b213d5 a3fc548 3b213d5 a3fc548 3b213d5 a3fc548 3b213d5  | 
								1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61  | 
								from fastapi import FastAPI, UploadFile, File
from fastapi.responses import JSONResponse
import shutil
import os
from application import *
from functions import *
#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
@app.post("/upload/")
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 = 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)
 |