Spaces:
Sleeping
Sleeping
Update app.py
Browse files1234567891 unmodified line1112131415161713 unmodified lines31323334353637383940414243444546474849import torchfrom fastapi import FastAPI, Request, Formfrom fastapi.responses import HTMLResponse, JSONResponsefrom fastapi.staticfiles import StaticFilesfrom fastapi.templating import Jinja2Templatesfrom transformers import AutoTokenizer, AutoModelForCausalLM# ---------------------------# Models1 unmodified lineMODEL_OPTIONS = {"DeepSeek Coder 1.3B": "deepseek-ai/deepseek-coder-1.3b-instruct","StarCoder 1B": "bigcode/starcoderbase-1b","CodeLLaMA 7B": "codellama/CodeLlama-7b-Instruct-hf"}loaded_models = {}13 unmodified lines# FastAPI setup# ---------------------------app = FastAPI()app.mount("/static", StaticFiles(directory="static"), name="static")templates = Jinja2Templates(directory=".")# ---------------------------# Routes# ---------------------------@app.get("/", response_class=HTMLResponse)async def home(request: Request):return templates.TemplateResponse("index.html", {"request": request, "models": list(MODEL_OPTIONS.keys())})@app.post("/chat")async def chat(user_input: str = Form(...), model_choice: str = Form(...), history: str = Form("[]")):import jsonhistory = json.loads(history)tokenizer, model = get_model(model_choice)123456781 unmodified line1011121314151613 unmodified lines30313233343536373839404142434445464748495051import torchfrom fastapi import FastAPI, Formfrom fastapi.responses import HTMLResponse, JSONResponse, FileResponsefrom transformers import AutoTokenizer, AutoModelForCausalLMimport json# ---------------------------# Models1 unmodified lineMODEL_OPTIONS = {"DeepSeek Coder 1.3B": "deepseek-ai/deepseek-coder-1.3b-instruct","StarCoder 1B": "bigcode/starcoderbase-1b","CodeLLaMA 7B": "codellama/CodeLLaMA-7b-Instruct-hf"}loaded_models = {}13 unmodified lines# FastAPI setup# ---------------------------app = FastAPI()# ---------------------------# Routes# ---------------------------@app.get("/", response_class=HTMLResponse)async def home():# Just serve index.html directly from rootreturn FileResponse("index.html")@app.get("/style.css")async def css():# Serve CSS directlyreturn FileResponse("style.css")@app.post("/chat")async def chat(user_input: str = Form(...), model_choice: str = Form(...), history: str = Form("[]")):history = json.loads(history)tokenizer, model = get_model(model_choice)
app.py+12-10