from fastapi import FastAPI from fastapi.staticfiles import StaticFiles from fastapi.responses import FileResponse from fastapi.responses import JSONResponse from fastapi import FastAPI, File, UploadFile from fastapi import FastAPI, File, UploadFile, Form from PIL import Image import io #from transformers import pipeline app = FastAPI() #pipe_flan = pipeline("text2text-generation", model="google/flan-t5-small") # @app.get("/infer_t5") # def t5(input): # output = pipe_flan(input) # return {"output": output[0]["generated_text"]} #app.mount("/", StaticFiles(directory="static", html=True), name="static") @app.get("/") def index() -> FileResponse: return FileResponse(path="./static/index.html", media_type="text/html") @app.get("/greeting/{name}") def get_greeting(name: str): return {"message": f"Hello, {name}!"} @app.post("/process_image") async def process_image(file: UploadFile = File(...)): try: contents = await file.read() image = Image.open(io.BytesIO(contents)) width, height = image.size return {"dimensions": f"{width} x {height}"} except Exception as e: print(f"Error processing image: {e}") return {"error": "Failed to process image"}