asony999 commited on
Commit
1f92523
·
verified ·
1 Parent(s): 9ac08a7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -8
app.py CHANGED
@@ -2,12 +2,12 @@ import streamlit as st
2
  from transformers import pipeline
3
 
4
  # Title of the app
5
- st.title("Multi-Task NLP App with Hugging Face Transformers")
6
  st.write("Explore advanced NLP tasks: Sentiment Analysis, Text Summarization, and Question Answering.")
7
 
8
  # Load pre-trained models
9
  sentiment_analyzer = pipeline("sentiment-analysis")
10
- summarizer = pipeline("summarization")
11
  qa_pipeline = pipeline("question-answering")
12
 
13
  # Sidebar for task selection
@@ -26,14 +26,24 @@ if task == "Sentiment Analysis":
26
 
27
  elif task == "Text Summarization":
28
  st.header("Text Summarization")
29
- user_input = st.text_area("Enter text to summarize:")
30
- if st.button("Summarize"):
31
- if user_input:
32
- result = summarizer(user_input, max_length=50, min_length=25, do_sample=False)
 
 
 
 
 
 
 
 
33
  st.write("Summary:")
34
  st.write(result[0]['summary_text'])
35
- else:
36
- st.write("Please enter some text to summarize.")
 
 
37
 
38
  elif task == "Question Answering":
39
  st.header("Question Answering")
 
2
  from transformers import pipeline
3
 
4
  # Title of the app
5
+ st.title("Multi-Task NLP App with Transformers")
6
  st.write("Explore advanced NLP tasks: Sentiment Analysis, Text Summarization, and Question Answering.")
7
 
8
  # Load pre-trained models
9
  sentiment_analyzer = pipeline("sentiment-analysis")
10
+ summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
11
  qa_pipeline = pipeline("question-answering")
12
 
13
  # Sidebar for task selection
 
26
 
27
  elif task == "Text Summarization":
28
  st.header("Text Summarization")
29
+ # User input
30
+ user_input = st.text_area("Enter text to summarize:")
31
+
32
+ # Summarization parameters
33
+ max_length = st.slider("Max Length of Summary", 50, 150, 100)
34
+ min_length = st.slider("Min Length of Summary", 10, 50, 25)
35
+
36
+ if st.button("Summarize"):
37
+ if user_input:
38
+ try:
39
+ # Generate summary
40
+ result = summarizer(user_input, max_length=max_length, min_length=min_length, do_sample=False)
41
  st.write("Summary:")
42
  st.write(result[0]['summary_text'])
43
+ except Exception as e:
44
+ st.error(f"An error occurred: {e}")
45
+ else:
46
+ st.write("Please enter some text to summarize.")
47
 
48
  elif task == "Question Answering":
49
  st.header("Question Answering")