Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,21 +1,19 @@
|
|
| 1 |
-
|
|
|
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
-
#
|
| 5 |
-
|
| 6 |
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
# Eğer model henüz yüklenmediyse, ilk istekte yükle
|
| 11 |
-
if pipe is None:
|
| 12 |
-
print("Model belleğe yükleniyor...")
|
| 13 |
-
pipe = pipeline("text-generation", model="Qwen/Qwen2.5-0.5B-Instruct", device="cpu")
|
| 14 |
-
|
| 15 |
-
# Prompt'u işleyip cevabı dön
|
| 16 |
-
output = pipe(prompt, max_new_tokens=256, do_sample=True, temperature=0.7)
|
| 17 |
-
return output[0]['generated_text']
|
| 18 |
|
| 19 |
-
#
|
| 20 |
-
|
| 21 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastapi import FastAPI
|
| 2 |
+
from pydantic import BaseModel
|
| 3 |
from transformers import pipeline
|
| 4 |
|
| 5 |
+
# FastAPI uygulamasını başlatıyoruz. HF Spaces "app" objesini otomatik tanıyıp uvicorn ile sunar.
|
| 6 |
+
app = FastAPI()
|
| 7 |
|
| 8 |
+
# Modeli sadece CPU kullanacak şekilde yüklüyoruz
|
| 9 |
+
pipe = pipeline("text-generation", model="Qwen/Qwen2.5-0.5B-Instruct", device="cpu")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
+
# Gelen JSON verisinin şemasını belirliyoruz
|
| 12 |
+
class GenerateRequest(BaseModel):
|
| 13 |
+
prompt: str
|
| 14 |
+
|
| 15 |
+
@app.post("/api/generate")
|
| 16 |
+
def generate(request: GenerateRequest):
|
| 17 |
+
# Gelen prompt'u modele verip sonucu döndürüyoruz
|
| 18 |
+
output = pipe(request.prompt, max_new_tokens=256, do_sample=True, temperature=0.7)
|
| 19 |
+
return {"response": output[0]['generated_text']}
|