varun500 commited on
Commit
9c8b074
·
1 Parent(s): 34e82be

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -15
app.py CHANGED
@@ -1,29 +1,33 @@
1
  import streamlit as st
2
  from transformers import pipeline, set_seed
3
 
4
- def generate_text(prompt):
5
- # Load the GPT-2 model
6
- generator = pipeline('text-generation', model='gpt2')
7
 
8
  # Set a random seed for reproducibility
9
  set_seed(1)
10
 
11
- # Generate text
12
- generated_text = generator(prompt, max_length=1000, num_return_sequences=1)[0]['generated_text']
13
 
14
- return generated_text
15
 
16
  def main():
17
  # Set the app title
18
- st.title("GPT-2 Text Generation")
19
-
20
- # Get user input
21
- prompt = st.text_input("Enter a prompt", "")
22
-
23
- # Generate text based on the prompt
24
- if prompt:
25
- generated_text = generate_text(prompt)
26
- st.write(generated_text)
 
 
 
 
27
 
28
  if __name__ == "__main__":
29
  main()
 
1
  import streamlit as st
2
  from transformers import pipeline, set_seed
3
 
4
+ def generate_summary(text):
5
+ # Load the summarization model
6
+ summarizer = pipeline("summarization", model="t5-base", max_length=1024, min_length=40)
7
 
8
  # Set a random seed for reproducibility
9
  set_seed(1)
10
 
11
+ # Generate summary
12
+ summary = summarizer(text, num_beams=4, no_repeat_ngram_size=2, length_penalty=2.0, early_stopping=True)[0]['summary_text']
13
 
14
+ return summary
15
 
16
  def main():
17
  # Set the app title
18
+ st.title("Text Summarizer")
19
+
20
+ # Create a text box for user input
21
+ input_text = st.text_area("Enter text to summarize", "")
22
+
23
+ # Create a button to generate the summary
24
+ if st.button("Summarize"):
25
+ # Generate summary based on user input
26
+ if input_text:
27
+ summary = generate_summary(input_text)
28
+ st.write(summary)
29
+ else:
30
+ st.warning("Please enter some text to summarize.")
31
 
32
  if __name__ == "__main__":
33
  main()