Delete app.py
Browse files
app.py
DELETED
|
@@ -1,76 +0,0 @@
|
|
| 1 |
-
from fastapi import FastAPI
|
| 2 |
-
from pydantic import BaseModel
|
| 3 |
-
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 4 |
-
import torch
|
| 5 |
-
|
| 6 |
-
app = FastAPI(title="Dexo Api")
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
MODEL_NAME = "TinyLlama/TinyLlama-1.1B-Chat-v1.0"
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
print("Model yükleniyor...")
|
| 13 |
-
|
| 14 |
-
tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME)
|
| 15 |
-
|
| 16 |
-
model = AutoModelForCausalLM.from_pretrained(
|
| 17 |
-
MODEL_NAME,
|
| 18 |
-
torch_dtype=torch.float16,
|
| 19 |
-
device_map="auto"
|
| 20 |
-
)
|
| 21 |
-
|
| 22 |
-
print("Model hazır!")
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
class RequestData(BaseModel):
|
| 26 |
-
message: str
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
@app.get("/")
|
| 30 |
-
def home():
|
| 31 |
-
return {
|
| 32 |
-
"status": "online",
|
| 33 |
-
"model": "TinyLlama 1.1B",
|
| 34 |
-
"api": "Dexo Api"
|
| 35 |
-
}
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
@app.post("/chat")
|
| 39 |
-
def chat(data: RequestData):
|
| 40 |
-
|
| 41 |
-
prompt = f"""
|
| 42 |
-
Sen Dexo AI asistanısın.
|
| 43 |
-
|
| 44 |
-
Kullanıcı:
|
| 45 |
-
{data.message}
|
| 46 |
-
|
| 47 |
-
Asistan:
|
| 48 |
-
"""
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
inputs = tokenizer(
|
| 52 |
-
prompt,
|
| 53 |
-
return_tensors="pt"
|
| 54 |
-
).to(model.device)
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
output = model.generate(
|
| 58 |
-
**inputs,
|
| 59 |
-
max_new_tokens=200,
|
| 60 |
-
temperature=0.7,
|
| 61 |
-
do_sample=True
|
| 62 |
-
)
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
result = tokenizer.decode(
|
| 66 |
-
output[0],
|
| 67 |
-
skip_special_tokens=True
|
| 68 |
-
)
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
answer = result.split("Asistan:")[-1]
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
return {
|
| 75 |
-
"response": answer.strip()
|
| 76 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|