Spaces:
Sleeping
Sleeping
Upload 5 files
Browse files- .dockerignore +5 -0
- Dockerfile +17 -0
- README.md +3 -11
- app.py +20 -0
- requirements.txt +5 -0
.dockerignore
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
__pycache__/
|
2 |
+
*.pyc
|
3 |
+
*.pyo
|
4 |
+
*.pyd
|
5 |
+
venv/
|
Dockerfile
ADDED
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Gunakan image Python yang ringan
|
2 |
+
FROM python:3.10-slim
|
3 |
+
|
4 |
+
# Set working directory
|
5 |
+
WORKDIR /app
|
6 |
+
|
7 |
+
# Salin dependensi
|
8 |
+
COPY requirements.txt .
|
9 |
+
|
10 |
+
# Install dependensi
|
11 |
+
RUN pip install --no-cache-dir -r requirements.txt
|
12 |
+
|
13 |
+
# Salin kode aplikasi
|
14 |
+
COPY . .
|
15 |
+
|
16 |
+
# Jalankan FastAPI
|
17 |
+
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
|
README.md
CHANGED
@@ -1,11 +1,3 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
|
4 |
-
colorFrom: gray
|
5 |
-
colorTo: pink
|
6 |
-
sdk: docker
|
7 |
-
pinned: false
|
8 |
-
license: mit
|
9 |
-
---
|
10 |
-
|
11 |
-
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
1 |
+
# Hello World
|
2 |
+
|
3 |
+
This is a simple repository to get started with GitHub.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app.py
ADDED
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from fastapi import FastAPI
|
2 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
3 |
+
import torch
|
4 |
+
|
5 |
+
app = FastAPI()
|
6 |
+
|
7 |
+
# Load model and tokenizer
|
8 |
+
tokenizer = AutoTokenizer.from_pretrained("unsloth/Llama-3.2-1B-Instruct")
|
9 |
+
model = AutoModelForCausalLM.from_pretrained("unsloth/Llama-3.2-1B-Instruct").to("cpu") # Gunakan CPU karena HF Spaces gratis hanya menyediakan CPU
|
10 |
+
|
11 |
+
@app.get("/")
|
12 |
+
def home():
|
13 |
+
return {"message": "FastAPI running with Llama-3.2-1B-Instruct"}
|
14 |
+
|
15 |
+
@app.post("/generate")
|
16 |
+
def generate_text(prompt: str):
|
17 |
+
inputs = tokenizer(prompt, return_tensors="pt").to("cpu") # Gunakan CPU
|
18 |
+
output = model.generate(**inputs, max_length=200)
|
19 |
+
generated_text = tokenizer.decode(output[0], skip_special_tokens=True)
|
20 |
+
return {"generated_text": generated_text}
|
requirements.txt
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
fastapi
|
2 |
+
uvicorn
|
3 |
+
transformers
|
4 |
+
torch
|
5 |
+
unsloth
|