Spaces:
Sleeping
Sleeping
File size: 1,541 Bytes
50d81d9 |
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 |
import gradio as gr
from transformers import LEDTokenizer, LEDForConditionalGeneration
import torch
# โหลดโมเดลและ tokenizer
model_name = "allenai/led-large-16384-arxiv"
tokenizer = LEDTokenizer.from_pretrained(model_name)
model = LEDForConditionalGeneration.from_pretrained(model_name)
# ฟังก์ชันสรุปข้อความ
def summarize_text(text, min_len=100, max_len=300):
inputs = tokenizer(text, return_tensors="pt", truncation=True, max_length=16384)
with torch.no_grad():
summary_ids = model.generate(
**inputs,
max_length=max_len,
min_length=min_len,
num_beams=4,
length_penalty=2.0
)
summary = tokenizer.decode(summary_ids[0], skip_special_tokens=True)
return summary
# UI Gradio
app = gr.Interface(
fn=summarize_text,
inputs=[
gr.Textbox(lines=15, placeholder="วางข้อความยาว ๆ ที่นี่...", label="Input Text"),
gr.Slider(50, 500, value=100, label="Minimum Summary Length"),
gr.Slider(100, 1000, value=300, label="Maximum Summary Length"),
],
outputs=gr.Textbox(label="Summarized Text"),
title="📄 Long Document Summarizer (LED 16k)",
description="ใช้โมเดล allenai/led-large-16384-arxiv สำหรับสรุปข้อความยาวมาก เช่น บทความ งานวิจัย หรือเอกสารหลายหน้า"
)
app.launch() |