Spaces:
Sleeping
Sleeping
Upload 4 files
Browse files
main.py
CHANGED
|
@@ -1,5 +1,6 @@
|
|
| 1 |
from fastapi import FastAPI, File, UploadFile
|
| 2 |
from fastapi.responses import JSONResponse
|
|
|
|
| 3 |
from PIL import Image
|
| 4 |
import io
|
| 5 |
import json
|
|
@@ -13,6 +14,11 @@ app = FastAPI(
|
|
| 13 |
"""
|
| 14 |
)
|
| 15 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
@app.post("/upload")
|
| 17 |
async def upload_image(fields:str, model:str, file: UploadFile = File(...)):
|
| 18 |
"""
|
|
@@ -57,7 +63,7 @@ async def upload_image(fields:str, model:str, file: UploadFile = File(...)):
|
|
| 57 |
except Exception as e:
|
| 58 |
return JSONResponse(content={"error": str(e)}, status_code=400)
|
| 59 |
|
| 60 |
-
@app.
|
| 61 |
async def list_models():
|
| 62 |
"""
|
| 63 |
### Endpoint Description:
|
|
@@ -66,4 +72,38 @@ async def list_models():
|
|
| 66 |
#### Response:
|
| 67 |
- A list of available models for text generation.
|
| 68 |
"""
|
| 69 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
from fastapi import FastAPI, File, UploadFile
|
| 2 |
from fastapi.responses import JSONResponse
|
| 3 |
+
from fastapi.middleware.cors import CORSMiddleware
|
| 4 |
from PIL import Image
|
| 5 |
import io
|
| 6 |
import json
|
|
|
|
| 14 |
"""
|
| 15 |
)
|
| 16 |
|
| 17 |
+
app.add_middleware(
|
| 18 |
+
CORSMiddleware,
|
| 19 |
+
allow_origins="*"
|
| 20 |
+
)
|
| 21 |
+
|
| 22 |
@app.post("/upload")
|
| 23 |
async def upload_image(fields:str, model:str, file: UploadFile = File(...)):
|
| 24 |
"""
|
|
|
|
| 63 |
except Exception as e:
|
| 64 |
return JSONResponse(content={"error": str(e)}, status_code=400)
|
| 65 |
|
| 66 |
+
@app.get("/models")
|
| 67 |
async def list_models():
|
| 68 |
"""
|
| 69 |
### Endpoint Description:
|
|
|
|
| 72 |
#### Response:
|
| 73 |
- A list of available models for text generation.
|
| 74 |
"""
|
| 75 |
+
|
| 76 |
+
models = [
|
| 77 |
+
{
|
| 78 |
+
"id": "gpt-4o-mini",
|
| 79 |
+
"description": "Latest model by OpenAI prefered for accuracy",
|
| 80 |
+
"title": "GPT-4.o Mini",
|
| 81 |
+
},
|
| 82 |
+
{
|
| 83 |
+
"id": "gpt-4o",
|
| 84 |
+
"description": "Latest model by OpenAI prefered for accuracy",
|
| 85 |
+
"title": "GPT-4.o",
|
| 86 |
+
},
|
| 87 |
+
{
|
| 88 |
+
"id": "deepseek-chat",
|
| 89 |
+
"description": "Latest model by Deepseek prefered for speed",
|
| 90 |
+
"title": "DeepSeek Chat",
|
| 91 |
+
},
|
| 92 |
+
{
|
| 93 |
+
"id": "claude-3-5-sonnet-20241022",
|
| 94 |
+
"description": "Latest model by Google for both accuracy and speed",
|
| 95 |
+
"title": "Claude 3.5 Sonnet 20241022",
|
| 96 |
+
},
|
| 97 |
+
{
|
| 98 |
+
"id": "llama_llm_d",
|
| 99 |
+
"description": "Latest model by Facebook for both accuracy and speed",
|
| 100 |
+
"title": "Llama LLM D",
|
| 101 |
+
},
|
| 102 |
+
{
|
| 103 |
+
"id": "llama_llm_o",
|
| 104 |
+
"description": "Latest model by Facebook for both accuracy and speed",
|
| 105 |
+
"title": "Llama LLM O",
|
| 106 |
+
}
|
| 107 |
+
]
|
| 108 |
+
|
| 109 |
+
return JSONResponse(content={"models": models})
|