sabssag commited on
Commit
c20a099
1 Parent(s): e3f1e79

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -32
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('./model')
12
-
13
- # Define the path to the saved model
14
- model_path = './model/T5_samsum-20240723T171755Z-001'
15
-
16
- # Load the tokenizer and model
17
- tokenizer = T5Tokenizer.from_pretrained(model_path)
18
- model = TFAutoModelForSeq2SeqLM.from_pretrained(model_path)
19
-
20
- summarizer = pipeline("summarization", model=model, tokenizer=tokenizer)
21
-
22
- # Set the title for the Streamlit app
23
- st.title("T5 Summary Generator")
24
-
25
- # Text input for the user
26
- text = st.text_area("Enter your text: ")
27
-
28
- def generate_summary(input_text):
29
- # Perform summarization
30
- summary = summarizer(input_text, max_length=200, min_length=40, do_sample=False)
31
- return summary[0]['summary_text']
32
-
33
- if st.button("Generate"):
34
- if text:
35
- generated_summary = generate_summary(text)
36
- # Display the generated summary
37
- st.subheader("Generated Summary")
38
- st.write(generated_summary)
39
- else:
40
- st.warning("Please enter some text to generate a summary.")
 
 
 
 
 
 
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.")