Spaces:
Sleeping
Sleeping
File size: 3,555 Bytes
6fabab2 190ca83 d7aaea6 6fabab2 190ca83 6fabab2 d7aaea6 6a40ad6 190ca83 d7aaea6 190ca83 6fabab2 d7aaea6 6fabab2 d7aaea6 6a40ad6 190ca83 d7aaea6 190ca83 d7aaea6 190ca83 7ef137c 190ca83 7ef137c d7aaea6 190ca83 7ef137c 190ca83 d7aaea6 2fdbd68 d7aaea6 190ca83 6a40ad6 d7aaea6 7ef137c 6fabab2 190ca83 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 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 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
import gradio as gr
import torch
from transformers import AutoTokenizer, AutoModelForCausalLM
from peft import PeftModel
import spaces
# 1. ๋ชจ๋ธ ID ์ค์
base_id = "Qwen/Qwen2.5-7B-Instruct"
adapter_id = "epinfomax/BizFlow-Summarizer-Ko"
# 2. ๋ชจ๋ธ ๋ก๋
print(f"๐ ๋ชจ๋ธ ๋ก๋ฉ ์ค...")
tokenizer = AutoTokenizer.from_pretrained(base_id)
model = AutoModelForCausalLM.from_pretrained(base_id, torch_dtype=torch.float16)
model = PeftModel.from_pretrained(model, adapter_id)
# 3. ์ถ๋ก ํจ์
@spaces.GPU
def summarize(text):
device = "cuda"
model.to(device)
messages = [
{"role": "system", "content": "๋น์ ์ ๋น์ฆ๋์ค ๋ฌธ์๋ฅผ ์ ๋ฌธ์ ์ผ๋ก ์์ฝํ๋ AI ์ด์์คํดํธ์
๋๋ค. ํต์ฌ ๋ด์ฉ์ ๋ช
ํํ๊ฒ ์์ฝํด ์ฃผ์ธ์."},
{"role": "user", "content": text}
]
input_text = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
inputs = tokenizer([input_text], return_tensors="pt").to(device)
with torch.no_grad():
outputs = model.generate(
**inputs,
max_new_tokens=512,
temperature=0.3,
repetition_penalty=1.1
)
generated_tokens = outputs[:, inputs.input_ids.shape[1]:]
result = tokenizer.batch_decode(generated_tokens, skip_special_tokens=True)
return result[0]
# โ
์์์ฉ ๊ธด ๋ฌธ์ฅ ๋ฐ์ดํฐ (์ค์ ๊ธฐ์ฌ ์คํ์ผ)
example_text = """์ผ์ฑ์ ์๊ฐ 2024๋
4๋ถ๊ธฐ ์ฐ๊ฒฐ ๊ธฐ์ค ๋งค์ถ 67์กฐ 7800์ต ์, ์์
์ด์ต 2์กฐ 8200์ต ์์ ๊ธฐ๋กํ๋ค๊ณ 31์ผ ํ์ ๊ณต์ํ๋ค.
์ ๋
๋๊ธฐ ๋๋น ๋งค์ถ์ 3.81% ๊ฐ์ํ๊ณ , ์์
์ด์ต์ 34.4% ์ค์๋ค. ๋ฉ๋ชจ๋ฆฌ ๋ฐ๋์ฒด ์ํฉ ํ๋ณต์ผ๋ก ์ ๋ถ๊ธฐ ๋๋น ๋งค์ถ๊ณผ ์์
์ด์ต์ ๊ฐ์ ๋๋ค.
๋ถ๋ฌธ๋ณ๋ก ๋ณด๋ฉด ๋ฐ๋์ฒด(DS) ๋ถ๋ฌธ์ ๋งค์ถ 21์กฐ 7000์ต ์, ์์
์์ค 2์กฐ 1800์ต ์์ ๊ธฐ๋กํ๋ค.
D๋จ์ ์ฌ๊ณ ์์ค์ด ํฐ ํญ์ผ๋ก ๊ฐ์ ๋ ๊ฐ์ด๋ฐ ํ์ ์ ํ์ ์ฑ๊ณตํ๋ค. ํ์ด๋๋ฆฌ๋ ์์ฅ ์์ ์นจ์ฒด๋ก ์ค์ ๋ถ์ง์ด ์ง์๋๋ค.
๋ชจ๋ฐ์ผ(MX)๊ณผ ๋คํธ์ํฌ ๋ถ๋ฌธ์ ๋งค์ถ 25์กฐ 400์ต ์, ์์
์ด์ต 2์กฐ 7300์ต ์์ ๋ฌ์ฑํ๋ค.
์ ์ ํ ์ถ์ ํจ๊ณผ๊ฐ ๋ํ๋๋ฉฐ ์ค๋งํธํฐ ํ๋งค๋์ ์ค์์ง๋ง, ํ๋ธ๋ฆฟ๊ณผ ์จ์ด๋ฌ๋ธ ์ ํ ํ๋งค๊ฐ ๊ฒฌ์กฐํ๋ค.
์์๋์คํ๋ ์ด(VD)์ ๊ฐ์ ๋ถ๋ฌธ์ ๋งค์ถ 14์กฐ 2200์ต ์, ์์
์์ค 500์ต ์์ ๊ธฐ๋กํ๋ค.
๊ธ๋ก๋ฒ TV ์์ ์ ์ฒด์๋ ํ๋ฆฌ๋ฏธ์ ์ ํ ์ค์ฌ์ผ๋ก ํ๋งค ๊ตฌ์กฐ๋ฅผ ๊ฐ์ ํ๋ค.
์ผ์ฑ์ ์๋ "์ฌํด 1๋ถ๊ธฐ์๋ IT ์ํฉ ํ๋ณต์ธ๊ฐ ๊ธฐ๋๋๋ ๋งํผ, ๊ณ ๋ถ๊ฐ๊ฐ์น ์ ํ ํ๋งค๋ฅผ ํ๋ํด ์์ต์ฑ ๊ฐ์ ์ ์ฃผ๋ ฅํ ๊ณํ"์ด๋ผ๊ณ ๋ฐํ๋ค.
ํนํ ์์ฑํ AI์ฉ ๊ณ ๋์ญํญ๋ฉ๋ชจ๋ฆฌ(HBM) ๋ฑ ์ ๋จ ๊ณต์ ์ ํ ํ๋งค๋ฅผ ๋ํญ ๋๋ฆด ๋ฐฉ์นจ์ด๋ค."""
# 4. ์น ์ธํฐํ์ด์ค ์ ์
iface = gr.Interface(
fn=summarize,
inputs=gr.Textbox(
lines=15,
placeholder="์์ฝํ ๋ฌธ์๋ฅผ ์ฌ๊ธฐ์ ๋ถ์ฌ๋ฃ์ผ์ธ์...",
label="์
๋ ฅ ๋ฌธ์"
),
outputs=gr.Textbox(
lines=10, # โ
๊ฒฐ๊ณผ์ฐฝ ๋์ด๋ฅผ 10์ค๋ก ๊ณ ์ ํ์ฌ ์์ํ๊ฒ ๋ง๋ฆ
label="์์ฝ ๊ฒฐ๊ณผ",
#show_copy_button=True # โ
๋ณต์ฌ ๋ฒํผ ์ถ๊ฐ (ํธ์์ฑ)
),
title="BizFlow ๋ฌธ์ ์์ฝ๊ธฐ",
description="Qwen2.5-7B + ํ์ธํ๋(LoRA) ๋ชจ๋ธ ํ
์คํธ ๋ฐ๋ชจ์
๋๋ค. (ZeroGPU)",
examples=[[example_text]] # โ
์์์ ์ ์ํ ๊ธด ๋ฌธ์ฅ์ ์์๋ก ๋ฃ์
)
if __name__ == "__main__":
iface.launch() |