Spaces:
Sleeping
Sleeping
Update main.py
Browse files
main.py
CHANGED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 2 |
+
import torch
|
| 3 |
+
|
| 4 |
+
# 무료 모델 선택 (Mistral 7B)
|
| 5 |
+
model_name = "mistralai/Mistral-7B-Instruct-v0.1"
|
| 6 |
+
|
| 7 |
+
# 토크나이저 및 모델 불러오기
|
| 8 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 9 |
+
model = AutoModelForCausalLM.from_pretrained(model_name, torch_dtype=torch.float16, device_map="auto")
|
| 10 |
+
|
| 11 |
+
def chat(user_input):
|
| 12 |
+
inputs = tokenizer(user_input, return_tensors="pt").to("cuda" if torch.cuda.is_available() else "cpu")
|
| 13 |
+
outputs = model.generate(**inputs, max_length=200)
|
| 14 |
+
return tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 15 |
+
|
| 16 |
+
# 테스트 실행
|
| 17 |
+
print(chat("Hello, how are you?"))
|