orgoflu commited on
Commit
a73e7cd
ยท
verified ยท
1 Parent(s): 9fea5b1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -7
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-Donut-CORDv2": "naver-clova-ix/donut-base-finetuned-cord-v2"
16
  }
17
 
18
- # ===== ๋ชจ๋ธ ๋กœ๋“œ (๋‘˜ ๋‹ค text-generation์œผ๋กœ) =====
19
- def load_text_model(model_name):
 
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
- # ===== ์žฌ์ž‘์„ฑ (QwenยทCLOVA ๊ณตํ†ต) =====
46
  def rewrite_with_llm(sentences, model_choice):
47
- llm_pipeline = load_text_model(MODEL_OPTIONS[model_choice])
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
- # ์žฌ์ž‘์„ฑ (QwenยทCLOVA ๋ชจ๋‘ ์ˆ˜ํ–‰)
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 ๋˜๋Š” CLOVA)๋กœ ์žฌ์ž‘์„ฑํ•ฉ๋‹ˆ๋‹ค."
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__":