Spaces:
Sleeping
Sleeping
File size: 4,377 Bytes
6b10203 7355d7a 6b10203 7edb88d 6b10203 759c6b8 6b10203 b7685d4 6b10203 b7685d4 6b10203 7355d7a 6b10203 7355d7a 759c6b8 7355d7a 759c6b8 7355d7a 759c6b8 6b10203 7355d7a 759c6b8 7355d7a 759c6b8 7355d7a 6b10203 759c6b8 7355d7a 759c6b8 7355d7a 759c6b8 6b10203 b7685d4 6b10203 7355d7a 6b10203 7355d7a 6b10203 7355d7a 759c6b8 7355d7a 759c6b8 7355d7a 759c6b8 b7685d4 759c6b8 7355d7a 759c6b8 7355d7a 759c6b8 b7685d4 6b10203 7355d7a 6b10203 7355d7a 759c6b8 7355d7a 759c6b8 6b10203 b7685d4 | 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 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 | import gradio as gr
import torch
import re
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
# =========================
# LOAD MODEL
# =========================
MODEL_ID = "imelia13/t5-indosum-summarizer"
tokenizer = AutoTokenizer.from_pretrained(MODEL_ID)
model = AutoModelForSeq2SeqLM.from_pretrained(MODEL_ID)
device = torch.device("cpu")
model.to(device)
# =========================
# TEXT PROCESSING
# =========================
def clean_text(text):
text = re.sub(r"\s+", " ", text.replace("\n", " ").replace("\t", " "))
return text.strip()
def summarize_text(text):
if not text or len(text.split()) < 10:
return "Teks terlalu pendek (minimal 10 kata)."
text = clean_text(text)
inputs = tokenizer(
"ringkas: " + text,
return_tensors="pt",
truncation=True,
max_length=512
).to(device)
with torch.no_grad():
outputs = model.generate(
**inputs,
max_length=128,
num_beams=4,
early_stopping=True
)
return tokenizer.decode(outputs[0], skip_special_tokens=True)
# =========================
# CUSTOM CSS
# =========================
custom_css = """
body {
background: radial-gradient(circle at top, #141a33, #0b0f1a);
font-family: Inter, system-ui, sans-serif;
}
.gradio-container {
max-width: 1100px !important;
margin: auto !important;
}
/* Cards */
.card {
background: rgba(255,255,255,0.04);
border-radius: 18px;
padding: 1.5rem;
box-shadow: 0 12px 32px rgba(0,0,0,0.3);
margin-bottom: 1.5rem;
}
/* Hero */
.hero {
text-align: center;
margin-bottom: 2.5rem;
}
.hero h1 {
font-size: 2.6rem;
margin-bottom: 0.3rem;
}
.hero p {
opacity: 0.8;
font-size: 1rem;
}
/* Info grid */
.info-grid {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 1rem;
}
.info-item {
font-size: 0.9rem;
opacity: 0.85;
}
/* Main app grid */
.app-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 1.5rem;
}
/* Responsive */
@media (max-width: 900px) {
.info-grid {
grid-template-columns: 1fr;
}
.app-grid {
grid-template-columns: 1fr;
}
}
/* Button */
button {
background: linear-gradient(135deg, #8b5cf6, #10b981) !important;
color: white !important;
font-weight: 600;
border-radius: 14px !important;
height: 48px;
}
/* Helper text */
.helper {
font-size: 0.8rem;
opacity: 0.65;
margin-top: 0.5rem;
}
"""
# =========================
# UI
# =========================
with gr.Blocks() as demo:
# HERO
gr.Markdown("""
<div class="hero">
<h1>AI Text Summarization</h1>
<p>Research-grade automatic summarization for Indonesian text</p>
</div>
""")
# INFO SECTION
gr.Markdown("""
<div class="card">
<div class="info-grid">
<div class="info-item">
<b>Fungsi</b><br/>
Meringkas artikel, berita, dan dokumen panjang secara otomatis.
</div>
<div class="info-item">
<b>Model</b><br/>
T5 IndoSum fine-tuned untuk Bahasa Indonesia.
</div>
<div class="info-item">
<b>Cara Pakai</b><br/>
Tempel teks → klik Generate → salin ringkasan.
</div>
</div>
</div>
""")
# MAIN APP
gr.Markdown('<div class="app-grid">')
# INPUT
gr.Markdown('<div class="card">')
gr.Markdown("### Input Artikel")
input_text = gr.Textbox(
lines=14,
placeholder="Masukkan teks artikel panjang di sini..."
)
gr.Markdown('<div class="helper">Minimal 10 kata • Maks ±500 kata</div>')
btn = gr.Button("Generate Summary")
gr.Markdown('</div>')
# OUTPUT
gr.Markdown('<div class="card">')
gr.Markdown("### Ringkasan")
output_text = gr.Textbox(
lines=14,
placeholder="Ringkasan akan muncul di sini..."
)
gr.Markdown('</div>')
gr.Markdown('</div>')
# ACTION
btn.click(
fn=summarize_text,
inputs=input_text,
outputs=output_text
)
# FOOTER
gr.Markdown("""
<center style="opacity:0.6; font-size:0.85rem; margin-top:2rem;">
© 2025 — AI Summarization System • Built with Gradio & Transformers
</center>
""")
demo.launch(
css=custom_css,
theme=gr.themes.Base()
)
|