Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -12,11 +12,12 @@ from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline
|
|
| 12 |
# ===== ๋ชจ๋ธ ๋ชฉ๋ก =====
|
| 13 |
MODEL_OPTIONS = {
|
| 14 |
"Qwen2.5-1.5B-Instruct": "Qwen/Qwen2.5-1.5B-Instruct",
|
| 15 |
-
"CLOVA-
|
| 16 |
}
|
| 17 |
|
| 18 |
-
# ===== ๋ชจ๋ธ ๋ก๋
|
| 19 |
-
def load_text_model(
|
|
|
|
| 20 |
tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)
|
| 21 |
model = AutoModelForCausalLM.from_pretrained(model_name, trust_remote_code=True).to("cpu")
|
| 22 |
return pipeline("text-generation", model=model, tokenizer=tokenizer, device=-1)
|
|
@@ -42,9 +43,9 @@ def summarize_text(text):
|
|
| 42 |
summarizer = TextRankSummarizer()
|
| 43 |
return [str(s) for s in summarizer(parser.document, sentence_count)]
|
| 44 |
|
| 45 |
-
# ===== ์ฌ์์ฑ
|
| 46 |
def rewrite_with_llm(sentences, model_choice):
|
| 47 |
-
llm_pipeline = load_text_model(
|
| 48 |
joined_text = "\n".join(sentences)
|
| 49 |
prompt = f"""๋ค์ ๋ฌธ์ฅ์ ์๋ฏธ๋ ์ ์งํ๋, ์๋ฌธ์ ์๋ ๋ด์ฉ์ ์ ๋ ์ถ๊ฐํ์ง ๋ง๊ณ ,
|
| 50 |
๋ฌธ์ฅ๋ง ๋ ์์ฐ์ค๋ฝ๊ฒ ๋ฐ๊ฟ์ฃผ์ธ์. ๋ค๋ฅธ ์ค๋ช
์ด๋ ๋ถ์ฐ ๋ฌธ์ฅ์ ์ฐ์ง ๋ง์ธ์.
|
|
@@ -74,7 +75,7 @@ def process_url(url, model_choice):
|
|
| 74 |
# ์์ฝ
|
| 75 |
summary_sentences = summarize_text(plain_text) or ["์์ฝ ์์"]
|
| 76 |
|
| 77 |
-
# ์ฌ์์ฑ
|
| 78 |
paraphrased_text = rewrite_with_llm(summary_sentences, model_choice)
|
| 79 |
|
| 80 |
return link_html + "<br><br>" + markdown_text, "\n".join(summary_sentences), paraphrased_text
|
|
@@ -94,7 +95,7 @@ iface = gr.Interface(
|
|
| 94 |
gr.Textbox(label="์๋ ์ฌ์์ฑ (LLM)", lines=5)
|
| 95 |
],
|
| 96 |
title="ํ๊ตญ์ด ๋ณธ๋ฌธ ์ถ์ถ + ์๋ ์์ฝ + LLM ์ฌ์์ฑ",
|
| 97 |
-
description="์๋ฌธ ํ
์คํธ์์ ๋ฐ๋ก ์์ฝ ํ, ์ ํํ ๋ชจ๋ธ(Qwen ๋๋
|
| 98 |
)
|
| 99 |
|
| 100 |
if __name__ == "__main__":
|
|
|
|
| 12 |
# ===== ๋ชจ๋ธ ๋ชฉ๋ก =====
|
| 13 |
MODEL_OPTIONS = {
|
| 14 |
"Qwen2.5-1.5B-Instruct": "Qwen/Qwen2.5-1.5B-Instruct",
|
| 15 |
+
"CLOVA-Text(๋์ฒด)": "kakaobrain/kogpt"
|
| 16 |
}
|
| 17 |
|
| 18 |
+
# ===== ํ
์คํธ ๋ชจ๋ธ ๋ก๋ =====
|
| 19 |
+
def load_text_model(model_choice):
|
| 20 |
+
model_name = MODEL_OPTIONS[model_choice]
|
| 21 |
tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)
|
| 22 |
model = AutoModelForCausalLM.from_pretrained(model_name, trust_remote_code=True).to("cpu")
|
| 23 |
return pipeline("text-generation", model=model, tokenizer=tokenizer, device=-1)
|
|
|
|
| 43 |
summarizer = TextRankSummarizer()
|
| 44 |
return [str(s) for s in summarizer(parser.document, sentence_count)]
|
| 45 |
|
| 46 |
+
# ===== ์ฌ์์ฑ =====
|
| 47 |
def rewrite_with_llm(sentences, model_choice):
|
| 48 |
+
llm_pipeline = load_text_model(model_choice)
|
| 49 |
joined_text = "\n".join(sentences)
|
| 50 |
prompt = f"""๋ค์ ๋ฌธ์ฅ์ ์๋ฏธ๋ ์ ์งํ๋, ์๋ฌธ์ ์๋ ๋ด์ฉ์ ์ ๋ ์ถ๊ฐํ์ง ๋ง๊ณ ,
|
| 51 |
๋ฌธ์ฅ๋ง ๋ ์์ฐ์ค๋ฝ๊ฒ ๋ฐ๊ฟ์ฃผ์ธ์. ๋ค๋ฅธ ์ค๋ช
์ด๋ ๋ถ์ฐ ๋ฌธ์ฅ์ ์ฐ์ง ๋ง์ธ์.
|
|
|
|
| 75 |
# ์์ฝ
|
| 76 |
summary_sentences = summarize_text(plain_text) or ["์์ฝ ์์"]
|
| 77 |
|
| 78 |
+
# ์ฌ์์ฑ
|
| 79 |
paraphrased_text = rewrite_with_llm(summary_sentences, model_choice)
|
| 80 |
|
| 81 |
return link_html + "<br><br>" + markdown_text, "\n".join(summary_sentences), paraphrased_text
|
|
|
|
| 95 |
gr.Textbox(label="์๋ ์ฌ์์ฑ (LLM)", lines=5)
|
| 96 |
],
|
| 97 |
title="ํ๊ตญ์ด ๋ณธ๋ฌธ ์ถ์ถ + ์๋ ์์ฝ + LLM ์ฌ์์ฑ",
|
| 98 |
+
description="์๋ฌธ ํ
์คํธ์์ ๋ฐ๋ก ์์ฝ ํ, ์ ํํ ๋ชจ๋ธ(Qwen ๋๋ KoGPT)๋ก ์ฌ์์ฑํฉ๋๋ค."
|
| 99 |
)
|
| 100 |
|
| 101 |
if __name__ == "__main__":
|