osmankoc commited on
Commit
d844f20
·
1 Parent(s): 115777a

Initial commit: FastAPI Hugging Face deployment

Browse files
Files changed (4) hide show
  1. .gitignore +21 -0
  2. Dockerfile +17 -0
  3. app.py +23 -0
  4. requirements.txt +5 -0
.gitignore ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Python derleme dosyaları
2
+ __pycache__/
3
+ *.py[cod]
4
+ *.so
5
+
6
+ # Sanal ortamlar
7
+ venv/
8
+ env/
9
+ *.env
10
+ *.venv
11
+
12
+ # Sistem dosyaları
13
+ .DS_Store
14
+ Thumbs.db
15
+
16
+ # Hugging Face Cache (Gereksiz model indirmelerini engeller)
17
+ ~/.cache/huggingface/
18
+
19
+ # Model ağırlıkları (Eğer büyük boyutlu modelleri manuel olarak eklediysen)
20
+ *.bin
21
+ *.h5
Dockerfile ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Resmi Python görüntüsünü kullan
2
+ FROM python:3.9
3
+
4
+ # Çalışma dizinini oluştur
5
+ WORKDIR /app
6
+
7
+ # Gerekli dosyaları kopyala
8
+ COPY requirements.txt requirements.txt
9
+
10
+ # Bağımlılıkları yükle
11
+ RUN pip install --no-cache-dir -r requirements.txt
12
+
13
+ # Ana uygulama dosyasını kopyala
14
+ COPY app.py app.py
15
+
16
+ # FastAPI çalıştır
17
+ CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
app.py ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import FastAPI
2
+ from transformers import AutoModelForCausalLM, AutoTokenizer
3
+ import torch
4
+
5
+ app = FastAPI()
6
+
7
+ MODEL_NAME = "osmankoc/llama-2-7b-zoa"
8
+ device = "cuda" if torch.cuda.is_available() else "cpu"
9
+
10
+ print(f"Loading model: {MODEL_NAME} on {device}...")
11
+ tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME)
12
+ model = AutoModelForCausalLM.from_pretrained(MODEL_NAME).to(device)
13
+
14
+ @app.get("/")
15
+ def home():
16
+ return {"message": "ZOA AI Model API is running!"}
17
+
18
+ @app.post("/generate/")
19
+ def generate_text(prompt: str):
20
+ inputs = tokenizer(prompt, return_tensors="pt").to(device)
21
+ output = model.generate(**inputs, max_length=500)
22
+ response = tokenizer.decode(output[0], skip_special_tokens=True)
23
+ return {"response": response}
requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ fastapi
2
+ uvicorn
3
+ torch
4
+ transformers
5
+ accelerate