Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# app.py
|
2 |
+
!pip install transformers
|
3 |
+
!pip install streamlit
|
4 |
+
|
5 |
+
import streamlit as st
|
6 |
+
from transformers import pipeline
|
7 |
+
from transformers import AutoModelForSeq2SeqLM, AutoTokenizer
|
8 |
+
import torch
|
9 |
+
import gdown
|
10 |
+
|
11 |
+
# Download the model from Google Drive
|
12 |
+
@st.cache(allow_output_mutation=True)
|
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, tokenizer = load_model_from_gdrive()
|
27 |
+
summarizer = pipeline("summarization", model=model, tokenizer=tokenizer)
|
28 |
+
|
29 |
+
# Streamlit app
|
30 |
+
st.title("Text Summarization App")
|
31 |
+
st.write("Enter the text you want to summarize:")
|
32 |
+
|
33 |
+
# Text input
|
34 |
+
user_input = st.text_area("Text to summarize", height=200)
|
35 |
+
|
36 |
+
# Summarize text
|
37 |
+
if st.button("Summarize"):
|
38 |
+
if user_input:
|
39 |
+
summary = summarizer(user_input, max_length=130, min_length=30, do_sample=False)
|
40 |
+
st.subheader("Summary:")
|
41 |
+
st.write(summary[0]['summary_text'])
|
42 |
+
else:
|
43 |
+
st.write("Please enter text to summarize.")
|