llmahmad commited on
Commit
174f0a6
·
verified ·
1 Parent(s): b77deb3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -27
app.py CHANGED
@@ -8,36 +8,39 @@ 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.")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ )