File size: 908 Bytes
ab04017
b06b189
215df44
 
ab04017
 
215df44
 
ab04017
 
 
 
215df44
b06b189
 
 
 
ab04017
 
b06b189
ab04017
b06b189
 
ab04017
215df44
ab04017
 
 
215df44
ab04017
 
215df44
ab04017
215df44
ab04017
 
308afe6
ab04017
 
308afe6
215df44
ab04017
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
from fastapi import FastAPI
from transformers import AutoTokenizer, AutoModelForCausalLM, AutoConfig
import torch

app = FastAPI()

model_name = "Jaswant1801/qwen_nutrisync"

tokenizer = AutoTokenizer.from_pretrained(
    model_name,
    trust_remote_code=True
)

# Load config and remove quantization
config = AutoConfig.from_pretrained(model_name)
config.quantization_config = None

model = AutoModelForCausalLM.from_pretrained(
    model_name,
    config=config,
    trust_remote_code=True,
    device_map="cpu",
    dtype=torch.float32
)

@app.get("/")
def home():
    return {"message": "NutriSync API running"}

@app.post("/generate")
def generate(prompt: str):

    inputs = tokenizer(prompt, return_tensors="pt")

    outputs = model.generate(
        **inputs,
        max_new_tokens=150
    )

    response = tokenizer.decode(outputs[0], skip_special_tokens=True)

    return {"response": response}