Spaces:
Paused
Paused
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastapi import FastAPI, UploadFile, File
|
| 2 |
+
from pydantic import BaseModel
|
| 3 |
+
from router import route_request
|
| 4 |
+
from PIL import Image
|
| 5 |
+
import io
|
| 6 |
+
|
| 7 |
+
app = FastAPI()
|
| 8 |
+
|
| 9 |
+
class ChatRequest(BaseModel):
|
| 10 |
+
prompt: str
|
| 11 |
+
|
| 12 |
+
@app.post("/chat")
|
| 13 |
+
async def chat(request: ChatRequest):
|
| 14 |
+
response = route_request(request.prompt)
|
| 15 |
+
return {"response": response}
|
| 16 |
+
|
| 17 |
+
@app.post("/chat-image")
|
| 18 |
+
async def chat_image(prompt: str, file: UploadFile = File(...)):
|
| 19 |
+
image_bytes = await file.read()
|
| 20 |
+
image = Image.open(io.BytesIO(image_bytes))
|
| 21 |
+
|
| 22 |
+
response = route_request(prompt, image=image)
|
| 23 |
+
return {"response": response}
|
| 24 |
+
|