Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -23,9 +23,9 @@ def clean_text(text):
|
|
| 23 |
|
| 24 |
def summarize_text(text):
|
| 25 |
if not text or len(text.split()) < 10:
|
| 26 |
-
return "
|
| 27 |
|
| 28 |
-
text = clean_text(
|
| 29 |
|
| 30 |
inputs = tokenizer(
|
| 31 |
"ringkas: " + text,
|
|
@@ -54,24 +54,65 @@ body {
|
|
| 54 |
}
|
| 55 |
|
| 56 |
.gradio-container {
|
| 57 |
-
max-width:
|
| 58 |
margin: auto !important;
|
| 59 |
}
|
| 60 |
|
| 61 |
-
|
|
|
|
| 62 |
background: rgba(255,255,255,0.04);
|
| 63 |
-
border-radius:
|
| 64 |
padding: 1.5rem;
|
|
|
|
| 65 |
margin-bottom: 1.5rem;
|
| 66 |
-
box-shadow: 0 10px 30px rgba(0,0,0,0.25);
|
| 67 |
}
|
| 68 |
|
| 69 |
-
|
|
|
|
| 70 |
text-align: center;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 71 |
opacity: 0.85;
|
| 72 |
-
margin-bottom: 2rem;
|
| 73 |
}
|
| 74 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 75 |
button {
|
| 76 |
background: linear-gradient(135deg, #8b5cf6, #10b981) !important;
|
| 77 |
color: white !important;
|
|
@@ -80,9 +121,10 @@ button {
|
|
| 80 |
height: 48px;
|
| 81 |
}
|
| 82 |
|
|
|
|
| 83 |
.helper {
|
| 84 |
-
font-size: 0.
|
| 85 |
-
opacity: 0.
|
| 86 |
margin-top: 0.5rem;
|
| 87 |
}
|
| 88 |
"""
|
|
@@ -92,41 +134,69 @@ button {
|
|
| 92 |
# =========================
|
| 93 |
with gr.Blocks() as demo:
|
| 94 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 95 |
gr.Markdown("""
|
| 96 |
-
<
|
| 97 |
-
|
| 98 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 99 |
</div>
|
| 100 |
""")
|
| 101 |
|
| 102 |
-
|
| 103 |
-
gr.Markdown(
|
|
|
|
|
|
|
|
|
|
|
|
|
| 104 |
input_text = gr.Textbox(
|
| 105 |
-
lines=
|
| 106 |
-
placeholder="
|
| 107 |
-
)
|
| 108 |
-
gr.Markdown(
|
| 109 |
-
'<div class="helper">Minimal 10 kata. Maksimal ±500 kata.</div>'
|
| 110 |
)
|
|
|
|
| 111 |
btn = gr.Button("Generate Summary")
|
| 112 |
gr.Markdown('</div>')
|
| 113 |
|
| 114 |
-
|
| 115 |
-
gr.Markdown(
|
|
|
|
| 116 |
output_text = gr.Textbox(
|
| 117 |
-
lines=
|
| 118 |
-
placeholder="
|
| 119 |
)
|
| 120 |
gr.Markdown('</div>')
|
| 121 |
|
|
|
|
|
|
|
|
|
|
| 122 |
btn.click(
|
| 123 |
fn=summarize_text,
|
| 124 |
inputs=input_text,
|
| 125 |
outputs=output_text
|
| 126 |
)
|
| 127 |
|
|
|
|
| 128 |
gr.Markdown("""
|
| 129 |
-
<center style="opacity:0.6; font-size:0.85rem; margin-top:
|
| 130 |
© 2025 — AI Summarization System • Built with Gradio & Transformers
|
| 131 |
</center>
|
| 132 |
""")
|
|
|
|
| 23 |
|
| 24 |
def summarize_text(text):
|
| 25 |
if not text or len(text.split()) < 10:
|
| 26 |
+
return "Teks terlalu pendek (minimal 10 kata)."
|
| 27 |
|
| 28 |
+
text = clean_text()
|
| 29 |
|
| 30 |
inputs = tokenizer(
|
| 31 |
"ringkas: " + text,
|
|
|
|
| 54 |
}
|
| 55 |
|
| 56 |
.gradio-container {
|
| 57 |
+
max-width: 1100px !important;
|
| 58 |
margin: auto !important;
|
| 59 |
}
|
| 60 |
|
| 61 |
+
/* Cards */
|
| 62 |
+
.card {
|
| 63 |
background: rgba(255,255,255,0.04);
|
| 64 |
+
border-radius: 18px;
|
| 65 |
padding: 1.5rem;
|
| 66 |
+
box-shadow: 0 12px 32px rgba(0,0,0,0.3);
|
| 67 |
margin-bottom: 1.5rem;
|
|
|
|
| 68 |
}
|
| 69 |
|
| 70 |
+
/* Hero */
|
| 71 |
+
.hero {
|
| 72 |
text-align: center;
|
| 73 |
+
margin-bottom: 2.5rem;
|
| 74 |
+
}
|
| 75 |
+
|
| 76 |
+
.hero h1 {
|
| 77 |
+
font-size: 2.6rem;
|
| 78 |
+
margin-bottom: 0.3rem;
|
| 79 |
+
}
|
| 80 |
+
|
| 81 |
+
.hero p {
|
| 82 |
+
opacity: 0.8;
|
| 83 |
+
font-size: 1rem;
|
| 84 |
+
}
|
| 85 |
+
|
| 86 |
+
/* Info grid */
|
| 87 |
+
.info-grid {
|
| 88 |
+
display: grid;
|
| 89 |
+
grid-template-columns: repeat(3, 1fr);
|
| 90 |
+
gap: 1rem;
|
| 91 |
+
}
|
| 92 |
+
|
| 93 |
+
.info-item {
|
| 94 |
+
font-size: 0.9rem;
|
| 95 |
opacity: 0.85;
|
|
|
|
| 96 |
}
|
| 97 |
|
| 98 |
+
/* Main app grid */
|
| 99 |
+
.app-grid {
|
| 100 |
+
display: grid;
|
| 101 |
+
grid-template-columns: 1fr 1fr;
|
| 102 |
+
gap: 1.5rem;
|
| 103 |
+
}
|
| 104 |
+
|
| 105 |
+
/* Responsive */
|
| 106 |
+
@media (max-width: 900px) {
|
| 107 |
+
.info-grid {
|
| 108 |
+
grid-template-columns: 1fr;
|
| 109 |
+
}
|
| 110 |
+
.app-grid {
|
| 111 |
+
grid-template-columns: 1fr;
|
| 112 |
+
}
|
| 113 |
+
}
|
| 114 |
+
|
| 115 |
+
/* Button */
|
| 116 |
button {
|
| 117 |
background: linear-gradient(135deg, #8b5cf6, #10b981) !important;
|
| 118 |
color: white !important;
|
|
|
|
| 121 |
height: 48px;
|
| 122 |
}
|
| 123 |
|
| 124 |
+
/* Helper text */
|
| 125 |
.helper {
|
| 126 |
+
font-size: 0.8rem;
|
| 127 |
+
opacity: 0.65;
|
| 128 |
margin-top: 0.5rem;
|
| 129 |
}
|
| 130 |
"""
|
|
|
|
| 134 |
# =========================
|
| 135 |
with gr.Blocks() as demo:
|
| 136 |
|
| 137 |
+
# HERO
|
| 138 |
+
gr.Markdown("""
|
| 139 |
+
<div class="hero">
|
| 140 |
+
<h1>AI Text Summarization</h1>
|
| 141 |
+
<p>Research-grade automatic summarization for Indonesian text</p>
|
| 142 |
+
</div>
|
| 143 |
+
""")
|
| 144 |
+
|
| 145 |
+
# INFO SECTION
|
| 146 |
gr.Markdown("""
|
| 147 |
+
<div class="card">
|
| 148 |
+
<div class="info-grid">
|
| 149 |
+
<div class="info-item">
|
| 150 |
+
<b>Fungsi</b><br/>
|
| 151 |
+
Meringkas artikel, berita, dan dokumen panjang secara otomatis.
|
| 152 |
+
</div>
|
| 153 |
+
<div class="info-item">
|
| 154 |
+
<b>Model</b><br/>
|
| 155 |
+
T5 IndoSum fine-tuned untuk Bahasa Indonesia.
|
| 156 |
+
</div>
|
| 157 |
+
<div class="info-item">
|
| 158 |
+
<b>Cara Pakai</b><br/>
|
| 159 |
+
Tempel teks → klik Generate → salin ringkasan.
|
| 160 |
+
</div>
|
| 161 |
+
</div>
|
| 162 |
</div>
|
| 163 |
""")
|
| 164 |
|
| 165 |
+
# MAIN APP
|
| 166 |
+
gr.Markdown('<div class="app-grid">')
|
| 167 |
+
|
| 168 |
+
# INPUT
|
| 169 |
+
gr.Markdown('<div class="card">')
|
| 170 |
+
gr.Markdown("### Input Artikel")
|
| 171 |
input_text = gr.Textbox(
|
| 172 |
+
lines=14,
|
| 173 |
+
placeholder="Masukkan teks artikel panjang di sini..."
|
|
|
|
|
|
|
|
|
|
| 174 |
)
|
| 175 |
+
gr.Markdown('<div class="helper">Minimal 10 kata • Maks ±500 kata</div>')
|
| 176 |
btn = gr.Button("Generate Summary")
|
| 177 |
gr.Markdown('</div>')
|
| 178 |
|
| 179 |
+
# OUTPUT
|
| 180 |
+
gr.Markdown('<div class="card">')
|
| 181 |
+
gr.Markdown("### Ringkasan")
|
| 182 |
output_text = gr.Textbox(
|
| 183 |
+
lines=14,
|
| 184 |
+
placeholder="Ringkasan akan muncul di sini..."
|
| 185 |
)
|
| 186 |
gr.Markdown('</div>')
|
| 187 |
|
| 188 |
+
gr.Markdown('</div>')
|
| 189 |
+
|
| 190 |
+
# ACTION
|
| 191 |
btn.click(
|
| 192 |
fn=summarize_text,
|
| 193 |
inputs=input_text,
|
| 194 |
outputs=output_text
|
| 195 |
)
|
| 196 |
|
| 197 |
+
# FOOTER
|
| 198 |
gr.Markdown("""
|
| 199 |
+
<center style="opacity:0.6; font-size:0.85rem; margin-top:2rem;">
|
| 200 |
© 2025 — AI Summarization System • Built with Gradio & Transformers
|
| 201 |
</center>
|
| 202 |
""")
|