Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -43,30 +43,53 @@ def summarize_text(text: str) -> str:
|
|
| 43 |
return tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 44 |
|
| 45 |
# ===========================
|
| 46 |
-
# Gradio
|
| 47 |
# ===========================
|
| 48 |
-
def
|
| 49 |
word_count = len(text.split())
|
|
|
|
| 50 |
if word_count < 10:
|
| 51 |
-
return "⚠️ Teks terlalu pendek (minimal 10 kata)."
|
| 52 |
-
|
|
|
|
| 53 |
|
| 54 |
-
#
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 69 |
|
| 70 |
-
|
| 71 |
-
if __name__ == "__main__":
|
| 72 |
-
iface.launch()
|
|
|
|
| 43 |
return tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 44 |
|
| 45 |
# ===========================
|
| 46 |
+
# Gradio Functions
|
| 47 |
# ===========================
|
| 48 |
+
def summarize_with_counter(text):
|
| 49 |
word_count = len(text.split())
|
| 50 |
+
char_count = len(text)
|
| 51 |
if word_count < 10:
|
| 52 |
+
return "⚠️ Teks terlalu pendek (minimal 10 kata).", word_count, char_count
|
| 53 |
+
summary = summarize_text(text)
|
| 54 |
+
return summary, word_count, char_count
|
| 55 |
|
| 56 |
+
# ===========================
|
| 57 |
+
# Gradio Layout
|
| 58 |
+
# ===========================
|
| 59 |
+
with gr.Blocks(css="""
|
| 60 |
+
body { background: radial-gradient(circle at top, #141a33, #0b0f1a); color: #e5e7eb; font-family: 'Space Grotesk', sans-serif; }
|
| 61 |
+
.gradio-container { max-width: 1200px; margin: auto; padding: 32px; }
|
| 62 |
+
h1, h2 { color: #e5e7eb; }
|
| 63 |
+
textarea { background-color: rgba(0,0,0,0.35); color: #e5e7eb; }
|
| 64 |
+
.output-textbox { background-color: rgba(0,0,0,0.35); color: #e5e7eb; }
|
| 65 |
+
button { background: linear-gradient(135deg, #8b5cf6, #10b981); color: white; }
|
| 66 |
+
""") as demo:
|
| 67 |
+
gr.Markdown("# AI Text Summarization")
|
| 68 |
+
gr.Markdown("Research-grade automatic summarization for Indonesian text")
|
| 69 |
+
|
| 70 |
+
with gr.Row():
|
| 71 |
+
with gr.Column():
|
| 72 |
+
input_text = gr.Textbox(
|
| 73 |
+
label="Input Artikel",
|
| 74 |
+
placeholder="Masukkan teks artikel panjang di sini...",
|
| 75 |
+
lines=15
|
| 76 |
+
)
|
| 77 |
+
word_count_display = gr.Label(label="Jumlah Kata")
|
| 78 |
+
char_count_display = gr.Label(label="Jumlah Karakter")
|
| 79 |
+
summarize_btn = gr.Button("Generate Summary")
|
| 80 |
+
|
| 81 |
+
with gr.Column():
|
| 82 |
+
output_summary = gr.Textbox(
|
| 83 |
+
label="Ringkasan",
|
| 84 |
+
interactive=False
|
| 85 |
+
)
|
| 86 |
+
|
| 87 |
+
def update_counter(text):
|
| 88 |
+
word_count = len(text.split())
|
| 89 |
+
char_count = len(text)
|
| 90 |
+
return word_count, char_count
|
| 91 |
+
|
| 92 |
+
input_text.change(fn=update_counter, inputs=input_text, outputs=[word_count_display, char_count_display])
|
| 93 |
+
summarize_btn.click(fn=summarize_with_counter, inputs=input_text, outputs=[output_summary, word_count_display, char_count_display])
|
| 94 |
|
| 95 |
+
demo.launch()
|
|
|
|
|
|