Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -8,36 +8,39 @@ from transformers import AutoModelForSeq2SeqLM, AutoTokenizer
|
|
| 8 |
import torch
|
| 9 |
import gdown
|
| 10 |
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
def load_model_from_gdrive():
|
| 14 |
-
url = https://drive.google.com/drive/folders/19P3ZcWor8znyaOMJgx_gaHuOyf4alnP3?usp=drive_link # Replace with your actual Google Drive link
|
| 15 |
-
output = 'model.zip'
|
| 16 |
-
gdown.download(url, output, quiet=False)
|
| 17 |
-
# Unzip the model
|
| 18 |
-
import zipfile
|
| 19 |
-
with zipfile.ZipFile(output, 'r') as zip_ref:
|
| 20 |
-
zip_ref.extractall('model')
|
| 21 |
-
# Load the model and tokenizer
|
| 22 |
-
model = AutoModelForSeq2SeqLM.from_pretrained('model')
|
| 23 |
-
tokenizer = AutoTokenizer.from_pretrained('model')
|
| 24 |
-
return model, tokenizer
|
| 25 |
|
| 26 |
-
model
|
| 27 |
-
|
| 28 |
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
|
| 33 |
-
|
| 34 |
-
|
| 35 |
|
| 36 |
-
|
| 37 |
if st.button("Summarize"):
|
| 38 |
-
if
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
|
|
|
| 42 |
else:
|
| 43 |
-
st.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
import torch
|
| 9 |
import gdown
|
| 10 |
|
| 11 |
+
import streamlit as st
|
| 12 |
+
from transformers import pipeline, AutoTokenizer, AutoModelForSeq2SeqLM
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
+
# Load the model and tokenizer
|
| 15 |
+
model_path = '.'
|
| 16 |
|
| 17 |
+
tokenizer = AutoTokenizer.from_pretrained(model_path)
|
| 18 |
+
model = AutoModelForSeq2SeqLM.from_pretrained(model_path)
|
| 19 |
+
summarizer = pipeline('summarization', model=model, tokenizer=tokenizer)
|
| 20 |
|
| 21 |
+
st.title("Text Summarization with Fine-Tuned Model")
|
| 22 |
+
st.write("Enter text to generate a summary using the fine-tuned summarization model.")
|
| 23 |
|
| 24 |
+
text = st.text_area("Input Text", height=200)
|
| 25 |
if st.button("Summarize"):
|
| 26 |
+
if text:
|
| 27 |
+
with st.spinner("Summarizing..."):
|
| 28 |
+
summary = summarizer(text, max_length=150, min_length=30, do_sample=False)
|
| 29 |
+
st.success("Summary Generated")
|
| 30 |
+
st.write(summary[0]['summary_text'])
|
| 31 |
else:
|
| 32 |
+
st.warning("Please enter some text to summarize.")
|
| 33 |
+
|
| 34 |
+
if __name__ == "__main__":
|
| 35 |
+
st.set_option('deprecation.showfileUploaderEncoding', False)
|
| 36 |
+
st.markdown(
|
| 37 |
+
"""
|
| 38 |
+
<style>
|
| 39 |
+
.reportview-container {
|
| 40 |
+
flex-direction: row;
|
| 41 |
+
justify-content: center;
|
| 42 |
+
}
|
| 43 |
+
</style>
|
| 44 |
+
""",
|
| 45 |
+
unsafe_allow_html=True
|
| 46 |
+
)
|