Spaces:
Runtime error
Runtime error
Commit ·
4b2477b
1
Parent(s): 9409ed8
Upload 2 files
Browse files- app.py +34 -0
- requirements.txt +3 -0
app.py
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
|
| 3 |
+
import torch
|
| 4 |
+
|
| 5 |
+
# โหลด tokenizer และโมเดล
|
| 6 |
+
model_name = "facebook/bart-large-cnn"
|
| 7 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 8 |
+
model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
|
| 9 |
+
|
| 10 |
+
def main():
|
| 11 |
+
st.title("Text Summarization App")
|
| 12 |
+
|
| 13 |
+
# สร้าง text area สำหรับป้อนข้อความ
|
| 14 |
+
text = st.text_area('Enter the text to summarize:', '')
|
| 15 |
+
|
| 16 |
+
# คลิกปุ่ม "Summarize" เพื่อสรุปข้อความ
|
| 17 |
+
if st.button('Summarize'):
|
| 18 |
+
if text:
|
| 19 |
+
# ใช้โมเดลเพื่อสร้างสรุปข้อความ
|
| 20 |
+
input_ids = tokenizer(text, return_tensors="pt", padding=True, truncation=True).input_ids
|
| 21 |
+
with torch.no_grad():
|
| 22 |
+
output_ids = model.generate(input_ids)
|
| 23 |
+
|
| 24 |
+
# แปลงผลลัพธ์กลับเป็นข้อความ
|
| 25 |
+
summary = tokenizer.decode(output_ids[0], skip_special_tokens=True)
|
| 26 |
+
|
| 27 |
+
# แสดงสรุปข้อความ
|
| 28 |
+
st.subheader("Summary:")
|
| 29 |
+
st.write(summary)
|
| 30 |
+
else:
|
| 31 |
+
st.warning("Please enter some text to summarize.")
|
| 32 |
+
|
| 33 |
+
if __name__ == "__main__":
|
| 34 |
+
main()
|
requirements.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
torch
|
| 2 |
+
transformers
|
| 3 |
+
altair<5
|