-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
27 lines (23 loc) · 755 Bytes
/
main.py
File metadata and controls
27 lines (23 loc) · 755 Bytes
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
# main.py
from fastapi import FastAPI, HTTPException
from fastapi.responses import HTMLResponse
from pydantic import BaseModel
from run_model import generate_response
app = FastAPI()
# Input schema for POST
class PromptRequest(BaseModel):
prompt: str
# POST endpoint to generate a response from the model
@app.post("/generate")
async def generate(prompt_request: PromptRequest):
try:
response = generate_response(prompt_request.prompt)
return {"response": response}
except Exception as e:
raise HTTPException(status_code=500, detail=str(e))
# GET endpoint to serve HTML page
@app.get("/")
async def serve_home():
with open ("index.html", "r") as f:
html = f.read()
return HTMLResponse(content=html)