Spaces:
Sleeping
Sleeping
Commit
ยท
be4bab2
1
Parent(s):
fac7345
- main.py +10 -5
- requirements.txt +2 -1
main.py
CHANGED
|
@@ -2,6 +2,7 @@ from fastapi import FastAPI
|
|
| 2 |
import torch
|
| 3 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 4 |
import os
|
|
|
|
| 5 |
|
| 6 |
# ๋ชจ๋ธ ๋ก๋ฉ์ ์ ์ญ์์ ํ ๋ฒ๋ง ์ํ
|
| 7 |
model = None
|
|
@@ -37,11 +38,15 @@ def load_model():
|
|
| 37 |
print(f"๋ชจ๋ธ ๋ก๋ฉ ์๋ฃ. ์ต์ข
์ฅ์น: {model_device}")
|
| 38 |
|
| 39 |
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
|
| 46 |
chat = [
|
| 47 |
{ "role": "user", "content": prompt_content },
|
|
|
|
| 2 |
import torch
|
| 3 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 4 |
import os
|
| 5 |
+
from pydantic import BaseModel
|
| 6 |
|
| 7 |
# ๋ชจ๋ธ ๋ก๋ฉ์ ์ ์ญ์์ ํ ๋ฒ๋ง ์ํ
|
| 8 |
model = None
|
|
|
|
| 38 |
print(f"๋ชจ๋ธ ๋ก๋ฉ ์๋ฃ. ์ต์ข
์ฅ์น: {model_device}")
|
| 39 |
|
| 40 |
|
| 41 |
+
class PromptRequest(BaseModel):
|
| 42 |
+
"""์ฌ์ฉ์ ํ๋กฌํํธ๋ฅผ ๋ด๋ ์์ฒญ ๋ณธ๋ฌธ ๊ตฌ์กฐ"""
|
| 43 |
+
prompt: str
|
| 44 |
+
@app.post("/generate")
|
| 45 |
+
def generate_response(request: PromptRequest):
|
| 46 |
+
"""POST ์์ฒญ ๋ณธ๋ฌธ์์ ํ๋กฌํํธ๋ฅผ ๋ฐ์ ๋ชจ๋ธ ์ถ๋ก ์ ์ํํ๊ณ ๊ฒฐ๊ณผ๋ฅผ ๋ฐํํฉ๋๋ค."""
|
| 47 |
+
# ์์ฒญ ๋ณธ๋ฌธ์์ prompt ๊ฐ์ ์ถ์ถ
|
| 48 |
+
prompt_content = request.prompt
|
| 49 |
+
print(f"์๋ก์ด ํ๋กฌํํธ ์์ : {prompt_content[:50]}...")
|
| 50 |
|
| 51 |
chat = [
|
| 52 |
{ "role": "user", "content": prompt_content },
|
requirements.txt
CHANGED
|
@@ -12,4 +12,5 @@ fastapi>=0.112
|
|
| 12 |
uvicorn[standard]>=0.30
|
| 13 |
peft>=0.11.1
|
| 14 |
unsloth
|
| 15 |
-
bitsandbytes==0.43.3
|
|
|
|
|
|
| 12 |
uvicorn[standard]>=0.30
|
| 13 |
peft>=0.11.1
|
| 14 |
unsloth
|
| 15 |
+
bitsandbytes==0.43.3
|
| 16 |
+
pydantic
|