Upload test_script.py with huggingface_hub
Browse files- test_script.py +105 -0
test_script.py
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# /// script
|
| 2 |
+
# dependencies = ["transformers", "peft", "torch", "accelerate", "datasets"]
|
| 3 |
+
# ///
|
| 4 |
+
|
| 5 |
+
"""HF Jobs์์ ๋ชจ๋ธ ํ
์คํธ"""
|
| 6 |
+
|
| 7 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 8 |
+
from peft import PeftModel
|
| 9 |
+
import torch
|
| 10 |
+
|
| 11 |
+
# ์ค์
|
| 12 |
+
BASE_MODEL = "Qwen/Qwen2.5-0.5B"
|
| 13 |
+
ADAPTER_MODEL = "epinfomax/youtube-thumbnail-trend-analyzer"
|
| 14 |
+
|
| 15 |
+
print("=" * 60)
|
| 16 |
+
print("YouTube ์ธ๋ค์ผ ํธ๋ ๋ ๋ถ์ ๋ชจ๋ธ ํ
์คํธ")
|
| 17 |
+
print("=" * 60)
|
| 18 |
+
|
| 19 |
+
# ๋ชจ๋ธ ๋ก๋
|
| 20 |
+
print("\n๋ชจ๋ธ ๋ก๋ ์ค...")
|
| 21 |
+
tokenizer = AutoTokenizer.from_pretrained(ADAPTER_MODEL)
|
| 22 |
+
|
| 23 |
+
base_model = AutoModelForCausalLM.from_pretrained(
|
| 24 |
+
BASE_MODEL,
|
| 25 |
+
torch_dtype=torch.float16,
|
| 26 |
+
device_map="auto",
|
| 27 |
+
trust_remote_code=True
|
| 28 |
+
)
|
| 29 |
+
|
| 30 |
+
model = PeftModel.from_pretrained(base_model, ADAPTER_MODEL)
|
| 31 |
+
model.eval()
|
| 32 |
+
print("๋ชจ๋ธ ๋ก๋ ์๋ฃ!")
|
| 33 |
+
|
| 34 |
+
# ํ
์คํธ ์
๋ ฅ
|
| 35 |
+
test_input = """๋ค์ ์ธ๋ค์ผ ๋ถ์๋ค์ ๋ณด๊ณ ์ค๋์ ํธ๋ ๋๋ฅผ ์์ฝํ๊ณ Midjourney ํ๋กฌํํธ๋ฅผ ์ถ์ฒํด์ค:
|
| 36 |
+
|
| 37 |
+
[์์
] ์์ํฌ - ์์ฌํ ๋จ์
|
| 38 |
+
- ๋ฐฐ๊ฒฝ: ์ค๋ ์ง์ ๊ทธ๋ผ๋ฐ์ด์
|
| 39 |
+
- ์ธ๋ฌผ: ์กธ๋ฆฐ ํ์ , ๊ณ ๊ฐ ์์
|
| 40 |
+
- ํ
์คํธ: '์์ฌํ ๋จ์' ํฐ์ ์ธ๋ฆฌํ์ฒด
|
| 41 |
+
- ๋ถ์๊ธฐ: ๊ฐ์ฑ์ , ์์ ์
|
| 42 |
+
|
| 43 |
+
[๊ฒ์] ์นผ๋ฐ๋ ์นด๋ฅดํ
|
| 44 |
+
- ๋ฐฐ๊ฒฝ: ์ด๋์ด ๊ฒ์ ํ๋ฉด
|
| 45 |
+
- ์ธ๋ฌผ: ๊ฒ์ ์บ๋ฆญํฐ๋ค
|
| 46 |
+
- ํ
์คํธ: '์ฐํ๋ณต๋กค' ๋
ธ๋์ ๊ตต์ ๊ธ์จ
|
| 47 |
+
- ๋ถ์๊ธฐ: ์ ๋จธ๋ฌ์ค, ๊ฐ๋ฒผ์ด
|
| 48 |
+
|
| 49 |
+
[์ํฐํ
์ธ๋จผํธ] ํฉ์ ๋ฏผ ์ ํ์ด
|
| 50 |
+
- ๋ฐฐ๊ฒฝ: ๋ฐฉ์ก ์คํ๋์ค
|
| 51 |
+
- ์ธ๋ฌผ: ํฉ์ ๋ฏผ, ์๋ ํ์
|
| 52 |
+
- ํ
์คํธ: ์์
|
| 53 |
+
- ๋ถ์๊ธฐ: ์ฝ๋ฏน, ์น๊ทผํจ
|
| 54 |
+
|
| 55 |
+
[๊ณผํ๊ธฐ์ ] ์์ดํฐ ์ ๊ธฐ์
|
| 56 |
+
- ๋ฐฐ๊ฒฝ: ๊น๋ํ ํฐ์/ํ์
|
| 57 |
+
- ์ธ๋ฌผ: ์์
|
| 58 |
+
- ํ
์คํธ: ๊ธฐ์ ๊ด๋ จ ํ
์คํธ
|
| 59 |
+
- ๋ถ์๊ธฐ: ๋ฏธ๋์ , ๊น๋ํจ
|
| 60 |
+
|
| 61 |
+
[๋
ธํ์ฐ] ๊ธฐ์84 ์์์ฅ
|
| 62 |
+
- ๋ฐฐ๊ฒฝ: ์์์ฅ, ํ๋์
|
| 63 |
+
- ์ธ๋ฌผ: ๊ธฐ์84, ๋ฐ์ด๋๋ ๋ชจ์ต
|
| 64 |
+
- ํ
์คํธ: '์ํ4๋' ๋นจ๊ฐ์
|
| 65 |
+
- ๋ถ์๊ธฐ: ๋์ ์ , ์ ๋จธ๋ฌ์ค"""
|
| 66 |
+
|
| 67 |
+
print("\n" + "=" * 60)
|
| 68 |
+
print("์
๋ ฅ:")
|
| 69 |
+
print("=" * 60)
|
| 70 |
+
print(test_input[:500] + "...")
|
| 71 |
+
|
| 72 |
+
# ์๋ต ์์ฑ
|
| 73 |
+
print("\n" + "=" * 60)
|
| 74 |
+
print("๋ชจ๋ธ ์๋ต ์์ฑ ์ค...")
|
| 75 |
+
print("=" * 60)
|
| 76 |
+
|
| 77 |
+
messages = [{"role": "user", "content": test_input}]
|
| 78 |
+
text = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
|
| 79 |
+
inputs = tokenizer(text, return_tensors="pt").to(model.device)
|
| 80 |
+
|
| 81 |
+
with torch.no_grad():
|
| 82 |
+
outputs = model.generate(
|
| 83 |
+
**inputs,
|
| 84 |
+
max_new_tokens=500,
|
| 85 |
+
temperature=0.7,
|
| 86 |
+
top_p=0.9,
|
| 87 |
+
do_sample=True,
|
| 88 |
+
pad_token_id=tokenizer.pad_token_id,
|
| 89 |
+
eos_token_id=tokenizer.eos_token_id,
|
| 90 |
+
)
|
| 91 |
+
|
| 92 |
+
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 93 |
+
|
| 94 |
+
# ํ๋กฌํํธ ๋ถ๋ถ ์ ๊ฑฐ
|
| 95 |
+
if "์ถ์ฒํด์ค:" in response:
|
| 96 |
+
response = response.split("์ถ์ฒํด์ค:")[-1].strip()
|
| 97 |
+
|
| 98 |
+
print("\n" + "=" * 60)
|
| 99 |
+
print("๋ชจ๋ธ ์ถ๋ ฅ:")
|
| 100 |
+
print("=" * 60)
|
| 101 |
+
print(response)
|
| 102 |
+
|
| 103 |
+
print("\n" + "=" * 60)
|
| 104 |
+
print("ํ
์คํธ ์๋ฃ!")
|
| 105 |
+
print("=" * 60)
|