Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,40 +1,48 @@
|
|
1 |
import streamlit as st
|
2 |
-
|
3 |
from transformers import T5Tokenizer, TFAutoModelForSeq2SeqLM, pipeline
|
4 |
-
|
5 |
import zipfile
|
|
|
|
|
6 |
# Define the path to the saved model zip file
|
7 |
zip_model_path = 'T5_samsum-20240723T171755Z-001.zip'
|
8 |
|
|
|
|
|
|
|
9 |
# Unzip the model
|
10 |
with zipfile.ZipFile(zip_model_path, 'r') as zip_ref:
|
11 |
-
zip_ref.extractall(
|
12 |
-
|
13 |
-
#
|
14 |
-
model_path = '
|
15 |
-
|
16 |
-
#
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import streamlit as st
|
|
|
2 |
from transformers import T5Tokenizer, TFAutoModelForSeq2SeqLM, pipeline
|
|
|
3 |
import zipfile
|
4 |
+
import os
|
5 |
+
|
6 |
# Define the path to the saved model zip file
|
7 |
zip_model_path = 'T5_samsum-20240723T171755Z-001.zip'
|
8 |
|
9 |
+
# Define the directory to extract the model
|
10 |
+
model_dir = './model'
|
11 |
+
|
12 |
# Unzip the model
|
13 |
with zipfile.ZipFile(zip_model_path, 'r') as zip_ref:
|
14 |
+
zip_ref.extractall(model_dir)
|
15 |
+
|
16 |
+
# After unzipping, the model should be in a specific directory, check the directory structure
|
17 |
+
model_path = os.path.join(model_dir, 'T5_samsum')
|
18 |
+
|
19 |
+
# Verify that the directory exists and contains the necessary files
|
20 |
+
if not os.path.exists(model_path):
|
21 |
+
st.error(f"Model directory {model_path} does not exist or is incorrect.")
|
22 |
+
else:
|
23 |
+
# Load the tokenizer and model
|
24 |
+
tokenizer = T5Tokenizer.from_pretrained(model_path)
|
25 |
+
model = TFAutoModelForSeq2SeqLM.from_pretrained(model_path)
|
26 |
+
|
27 |
+
# Create a summarization pipeline
|
28 |
+
summarizer = pipeline("summarization", model=model, tokenizer=tokenizer)
|
29 |
+
|
30 |
+
# Set the title for the Streamlit app
|
31 |
+
st.title("T5 Summary Generator")
|
32 |
+
|
33 |
+
# Text input for the user
|
34 |
+
text = st.text_area("Enter your text: ")
|
35 |
+
|
36 |
+
def generate_summary(input_text):
|
37 |
+
# Perform summarization
|
38 |
+
summary = summarizer(input_text, max_length=200, min_length=40, do_sample=False)
|
39 |
+
return summary[0]['summary_text']
|
40 |
+
|
41 |
+
if st.button("Generate"):
|
42 |
+
if text:
|
43 |
+
generated_summary = generate_summary(text)
|
44 |
+
# Display the generated summary
|
45 |
+
st.subheader("Generated Summary")
|
46 |
+
st.write(generated_summary)
|
47 |
+
else:
|
48 |
+
st.warning("Please enter some text to generate a summary.")
|