File size: 627 Bytes
39cc8a5
a5dd7cf
a5b1f33
a5dd7cf
 
39cc8a5
 
 
 
 
 
a5b1f33
 
 
a5dd7cf
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
from fastapi import FastAPI
from transformers import AutoModel, AutoTokenizer

tokenizer = AutoTokenizer.from_pretrained("Qwen/Qwen3-0.6B")
model = AutoModel.from_pretrained("Qwen/Qwen3-0.6B")

app = FastAPI()

@app.get("/")
def greet_json():
    return {"Hello": "World!"}

@app.get("/message?input={0}")
def message(req):
    inputs = tokenizer(req.query.input, return_tensors="pt", padding=True, truncation=True)
    output = model.generate(
        input_ids=inputs["input_ids"],
        attention_mask=inputs["attention_mask"],
        temperature=0.3
    )
    return tokenizer.decode(output[0], skip_special_tokens=True)