Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,43 +2,30 @@ import gradio as gr
|
|
| 2 |
import torch
|
| 3 |
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 4 |
from peft import PeftModel
|
| 5 |
-
import spaces
|
| 6 |
|
| 7 |
# 1. ๋ชจ๋ธ ID ์ค์
|
| 8 |
base_id = "Qwen/Qwen2.5-7B-Instruct"
|
| 9 |
adapter_id = "epinfomax/BizFlow-Summarizer-Ko"
|
| 10 |
|
| 11 |
-
# 2. ๋ชจ๋ธ ๋ก๋
|
| 12 |
print(f"๐ ๋ชจ๋ธ ๋ก๋ฉ ์ค...")
|
| 13 |
-
|
| 14 |
tokenizer = AutoTokenizer.from_pretrained(base_id)
|
| 15 |
-
model = AutoModelForCausalLM.from_pretrained(base_id, torch_dtype=torch.float16)
|
| 16 |
model = PeftModel.from_pretrained(model, adapter_id)
|
| 17 |
|
| 18 |
-
# 3. ์ถ๋ก ํจ์
|
| 19 |
-
@spaces.GPU
|
| 20 |
def summarize(text):
|
| 21 |
-
|
| 22 |
-
device
|
| 23 |
-
model.to(device)
|
| 24 |
|
| 25 |
messages = [
|
| 26 |
-
{
|
| 27 |
-
|
| 28 |
-
"content": "๋น์ ์ ๋น์ฆ๋์ค ๋ฌธ์๋ฅผ ์ ๋ฌธ์ ์ผ๋ก ์์ฝํ๋ AI ์ด์์คํดํธ์
๋๋ค. ํต์ฌ ๋ด์ฉ์ ๋ช
ํํ๊ฒ ์์ฝํด ์ฃผ์ธ์."
|
| 29 |
-
},
|
| 30 |
-
{
|
| 31 |
-
"role": "user",
|
| 32 |
-
"content": text
|
| 33 |
-
}
|
| 34 |
]
|
| 35 |
|
| 36 |
-
input_text = tokenizer.apply_chat_template(
|
| 37 |
-
messages,
|
| 38 |
-
tokenize=False,
|
| 39 |
-
add_generation_prompt=True
|
| 40 |
-
)
|
| 41 |
-
|
| 42 |
inputs = tokenizer([input_text], return_tensors="pt").to(device)
|
| 43 |
|
| 44 |
with torch.no_grad():
|
|
@@ -54,6 +41,21 @@ def summarize(text):
|
|
| 54 |
|
| 55 |
return result[0]
|
| 56 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
# 4. ์น ์ธํฐํ์ด์ค ์ ์
|
| 58 |
iface = gr.Interface(
|
| 59 |
fn=summarize,
|
|
@@ -62,10 +64,14 @@ iface = gr.Interface(
|
|
| 62 |
placeholder="์์ฝํ ๋ฌธ์๋ฅผ ์ฌ๊ธฐ์ ๋ถ์ฌ๋ฃ์ผ์ธ์...",
|
| 63 |
label="์
๋ ฅ ๋ฌธ์"
|
| 64 |
),
|
| 65 |
-
outputs=gr.Textbox(
|
|
|
|
|
|
|
|
|
|
|
|
|
| 66 |
title="BizFlow ๋ฌธ์ ์์ฝ๊ธฐ",
|
| 67 |
description="Qwen2.5-7B + ํ์ธํ๋(LoRA) ๋ชจ๋ธ ํ
์คํธ ๋ฐ๋ชจ์
๋๋ค. (ZeroGPU)",
|
| 68 |
-
examples=[[
|
| 69 |
)
|
| 70 |
|
| 71 |
if __name__ == "__main__":
|
|
|
|
| 2 |
import torch
|
| 3 |
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 4 |
from peft import PeftModel
|
| 5 |
+
import spaces
|
| 6 |
|
| 7 |
# 1. ๋ชจ๋ธ ID ์ค์
|
| 8 |
base_id = "Qwen/Qwen2.5-7B-Instruct"
|
| 9 |
adapter_id = "epinfomax/BizFlow-Summarizer-Ko"
|
| 10 |
|
| 11 |
+
# 2. ๋ชจ๋ธ ๋ก๋
|
| 12 |
print(f"๐ ๋ชจ๋ธ ๋ก๋ฉ ์ค...")
|
|
|
|
| 13 |
tokenizer = AutoTokenizer.from_pretrained(base_id)
|
| 14 |
+
model = AutoModelForCausalLM.from_pretrained(base_id, torch_dtype=torch.float16)
|
| 15 |
model = PeftModel.from_pretrained(model, adapter_id)
|
| 16 |
|
| 17 |
+
# 3. ์ถ๋ก ํจ์
|
| 18 |
+
@spaces.GPU
|
| 19 |
def summarize(text):
|
| 20 |
+
device = "cuda"
|
| 21 |
+
model.to(device)
|
|
|
|
| 22 |
|
| 23 |
messages = [
|
| 24 |
+
{"role": "system", "content": "๋น์ ์ ๋น์ฆ๋์ค ๋ฌธ์๋ฅผ ์ ๋ฌธ์ ์ผ๋ก ์์ฝํ๋ AI ์ด์์คํดํธ์
๋๋ค. ํต์ฌ ๋ด์ฉ์ ๋ช
ํํ๊ฒ ์์ฝํด ์ฃผ์ธ์."},
|
| 25 |
+
{"role": "user", "content": text}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
]
|
| 27 |
|
| 28 |
+
input_text = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
inputs = tokenizer([input_text], return_tensors="pt").to(device)
|
| 30 |
|
| 31 |
with torch.no_grad():
|
|
|
|
| 41 |
|
| 42 |
return result[0]
|
| 43 |
|
| 44 |
+
# โ
์์์ฉ ๊ธด ๋ฌธ์ฅ ๋ฐ์ดํฐ (์ค์ ๊ธฐ์ฌ ์คํ์ผ)
|
| 45 |
+
example_text = """์ผ์ฑ์ ์๊ฐ 2024๋
4๋ถ๊ธฐ ์ฐ๊ฒฐ ๊ธฐ์ค ๋งค์ถ 67์กฐ 7800์ต ์, ์์
์ด์ต 2์กฐ 8200์ต ์์ ๊ธฐ๋กํ๋ค๊ณ 31์ผ ํ์ ๊ณต์ํ๋ค.
|
| 46 |
+
|
| 47 |
+
์ ๋
๋๊ธฐ ๋๋น ๋งค์ถ์ 3.81% ๊ฐ์ํ๊ณ , ์์
์ด์ต์ 34.4% ์ค์๋ค. ๋ฉ๋ชจ๋ฆฌ ๋ฐ๋์ฒด ์ํฉ ํ๋ณต์ผ๋ก ์ ๋ถ๊ธฐ ๋๋น ๋งค์ถ๊ณผ ์์
์ด์ต์ ๊ฐ์ ๋๋ค.
|
| 48 |
+
๋ถ๋ฌธ๋ณ๋ก ๋ณด๋ฉด ๋ฐ๋์ฒด(DS) ๋ถ๋ฌธ์ ๋งค์ถ 21์กฐ 7000์ต ์, ์์
์์ค 2์กฐ 1800์ต ์์ ๊ธฐ๋กํ๋ค.
|
| 49 |
+
D๋จ์ ์ฌ๊ณ ์์ค์ด ํฐ ํญ์ผ๋ก ๊ฐ์ ๋ ๊ฐ์ด๋ฐ ํ์ ์ ํ์ ์ฑ๊ณตํ๋ค. ํ์ด๋๋ฆฌ๋ ์์ฅ ์์ ์นจ์ฒด๋ก ์ค์ ๋ถ์ง์ด ์ง์๋๋ค.
|
| 50 |
+
|
| 51 |
+
๋ชจ๋ฐ์ผ(MX)๊ณผ ๋คํธ์ํฌ ๋ถ๋ฌธ์ ๋งค์ถ 25์กฐ 400์ต ์, ์์
์ด์ต 2์กฐ 7300์ต ์์ ๋ฌ์ฑํ๋ค.
|
| 52 |
+
์ ์ ํ ์ถ์ ํจ๊ณผ๊ฐ ๋ํ๋๋ฉฐ ์ค๋งํธํฐ ํ๋งค๋์ ์ค์์ง๋ง, ํ๋ธ๋ฆฟ๊ณผ ์จ์ด๋ฌ๋ธ ์ ํ ํ๋งค๊ฐ ๊ฒฌ์กฐํ๋ค.
|
| 53 |
+
์์๋์คํ๋ ์ด(VD)์ ๊ฐ์ ๋ถ๋ฌธ์ ๋งค์ถ 14์กฐ 2200์ต ์, ์์
์์ค 500์ต ์์ ๊ธฐ๋กํ๋ค.
|
| 54 |
+
๊ธ๋ก๋ฒ TV ์์ ์ ์ฒด์๋ ํ๋ฆฌ๋ฏธ์ ์ ํ ์ค์ฌ์ผ๋ก ํ๋งค ๊ตฌ์กฐ๋ฅผ ๊ฐ์ ํ๋ค.
|
| 55 |
+
|
| 56 |
+
์ผ์ฑ์ ์๋ "์ฌํด 1๋ถ๊ธฐ์๋ IT ์ํฉ ํ๋ณต์ธ๊ฐ ๊ธฐ๋๋๋ ๋งํผ, ๊ณ ๋ถ๊ฐ๊ฐ์น ์ ํ ํ๋งค๋ฅผ ํ๋ํด ์์ต์ฑ ๊ฐ์ ์ ์ฃผ๋ ฅํ ๊ณํ"์ด๋ผ๊ณ ๋ฐํ๋ค.
|
| 57 |
+
ํนํ ์์ฑํ AI์ฉ ๊ณ ๋์ญํญ๋ฉ๋ชจ๋ฆฌ(HBM) ๋ฑ ์ ๋จ ๊ณต์ ์ ํ ํ๋งค๋ฅผ ๋ํญ ๋๋ฆด ๋ฐฉ์นจ์ด๋ค."""
|
| 58 |
+
|
| 59 |
# 4. ์น ์ธํฐํ์ด์ค ์ ์
|
| 60 |
iface = gr.Interface(
|
| 61 |
fn=summarize,
|
|
|
|
| 64 |
placeholder="์์ฝํ ๋ฌธ์๋ฅผ ์ฌ๊ธฐ์ ๋ถ์ฌ๋ฃ์ผ์ธ์...",
|
| 65 |
label="์
๋ ฅ ๋ฌธ์"
|
| 66 |
),
|
| 67 |
+
outputs=gr.Textbox(
|
| 68 |
+
lines=10, # โ
๊ฒฐ๊ณผ์ฐฝ ๋์ด๋ฅผ 10์ค๋ก ๊ณ ์ ํ์ฌ ์์ํ๊ฒ ๋ง๋ฆ
|
| 69 |
+
label="์์ฝ ๊ฒฐ๊ณผ",
|
| 70 |
+
show_copy_button=True # โ
๋ณต์ฌ ๋ฒํผ ์ถ๊ฐ (ํธ์์ฑ)
|
| 71 |
+
),
|
| 72 |
title="BizFlow ๋ฌธ์ ์์ฝ๊ธฐ",
|
| 73 |
description="Qwen2.5-7B + ํ์ธํ๋(LoRA) ๋ชจ๋ธ ํ
์คํธ ๋ฐ๋ชจ์
๋๋ค. (ZeroGPU)",
|
| 74 |
+
examples=[[example_text]] # โ
์์์ ์ ์ํ ๊ธด ๋ฌธ์ฅ์ ์์๋ก ๋ฃ์
|
| 75 |
)
|
| 76 |
|
| 77 |
if __name__ == "__main__":
|