Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,36 +1,21 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
from transformers import
|
| 3 |
-
import time
|
| 4 |
|
| 5 |
-
|
| 6 |
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
model="sshleifer/distilbart-cnn-12-6",
|
| 10 |
-
tokenizer="sshleifer/distilbart-cnn-12-6",
|
| 11 |
-
framework="pt",
|
| 12 |
-
device=-1 # CPU κ°μ (Huggingface GPU νκ²½ λΆμμ λλΉ)
|
| 13 |
-
)
|
| 14 |
-
|
| 15 |
-
print("β
λͺ¨λΈ λ‘λ© μλ£")
|
| 16 |
|
| 17 |
def summarize(text):
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
elapsed = round(time.time() - start, 2)
|
| 23 |
-
output = result[0]['summary_text']
|
| 24 |
-
print("β
μμ½ κ²°κ³Ό:", output)
|
| 25 |
-
return f"β
μ²λ¦¬ μκ°: {elapsed}μ΄\n\n{output}"
|
| 26 |
-
except Exception as e:
|
| 27 |
-
print("β μμ½ μ€ν¨:", e)
|
| 28 |
-
return f"β μλ¬ λ°μ: {e}"
|
| 29 |
|
| 30 |
gr.Interface(
|
| 31 |
fn=summarize,
|
| 32 |
-
inputs=gr.Textbox(lines=
|
| 33 |
outputs="text",
|
| 34 |
-
title="CW AI μμ½ λΉμ (
|
| 35 |
-
description="
|
| 36 |
-
).launch(
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
|
|
|
|
| 3 |
|
| 4 |
+
model_name = "google/pegasus-cnn_dailymail"
|
| 5 |
|
| 6 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 7 |
+
model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
def summarize(text):
|
| 10 |
+
inputs = tokenizer(text, truncation=True, padding="longest", return_tensors="pt")
|
| 11 |
+
summary_ids = model.generate(inputs["input_ids"], max_length=100, num_beams=4, early_stopping=True)
|
| 12 |
+
summary = tokenizer.decode(summary_ids[0], skip_special_tokens=True)
|
| 13 |
+
return summary
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
gr.Interface(
|
| 16 |
fn=summarize,
|
| 17 |
+
inputs=gr.Textbox(lines=8, placeholder="μμ½ν κΈ΄ κΈμ μ
λ ₯νμΈμ"),
|
| 18 |
outputs="text",
|
| 19 |
+
title="CW AI μμ½ λΉμ (Pegasus)",
|
| 20 |
+
description="Pegasus λͺ¨λΈμ κΈ°λ°μΌλ‘ κ³ μ λ° μμ½μ μμ±ν©λλ€."
|
| 21 |
+
).launch()
|