Update app.py
Browse files
app.py
CHANGED
@@ -3,22 +3,28 @@ from fastapi import FastAPI
|
|
3 |
|
4 |
|
5 |
MODEL_ID = "MBZUAI/LaMini-Flan-T5-77M"
|
6 |
-
|
7 |
-
|
8 |
tokenizer = AutoTokenizer.from_pretrained(MODEL_ID)
|
9 |
model = AutoModelForSeq2SeqLM.from_pretrained(MODEL_ID)
|
10 |
|
11 |
app = FastAPI()
|
12 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
@app.get("/chat")
|
14 |
def chat(query: str):
|
15 |
"""
|
16 |
-
GET /chat?query=
|
17 |
Returns JSON: {"answer": "...model’s reply..."}
|
18 |
"""
|
|
|
19 |
inputs = tokenizer(query, return_tensors="pt")
|
|
|
20 |
outputs = model.generate(**inputs, max_new_tokens=100)
|
21 |
-
|
22 |
-
|
23 |
-
)
|
24 |
return {"answer": response.strip()}
|
|
|
3 |
|
4 |
|
5 |
MODEL_ID = "MBZUAI/LaMini-Flan-T5-77M"
|
|
|
|
|
6 |
tokenizer = AutoTokenizer.from_pretrained(MODEL_ID)
|
7 |
model = AutoModelForSeq2SeqLM.from_pretrained(MODEL_ID)
|
8 |
|
9 |
app = FastAPI()
|
10 |
|
11 |
+
@app.get("/")
|
12 |
+
def root():
|
13 |
+
return {
|
14 |
+
"message": "✅ LaMini-Flan-T5-77M Chatbot is running!",
|
15 |
+
"usage": "Send GET /chat?query=your+question"
|
16 |
+
}
|
17 |
+
|
18 |
@app.get("/chat")
|
19 |
def chat(query: str):
|
20 |
"""
|
21 |
+
Example: GET /chat?query=What+is+Python%3F
|
22 |
Returns JSON: {"answer": "...model’s reply..."}
|
23 |
"""
|
24 |
+
|
25 |
inputs = tokenizer(query, return_tensors="pt")
|
26 |
+
|
27 |
outputs = model.generate(**inputs, max_new_tokens=100)
|
28 |
+
|
29 |
+
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
|
|
30 |
return {"answer": response.strip()}
|