shubhammukherjee commited on
Commit
5f8cfa2
·
verified ·
1 Parent(s): 6b672ec

Created App

Browse files
Files changed (1) hide show
  1. app.py +18 -31
app.py CHANGED
@@ -1,38 +1,25 @@
1
  import streamlit as st
2
  from transformers import pipeline
3
 
4
- # Title of the app
5
- st.title("Hugging Face Transformers with Streamlit")
6
 
7
- # Sidebar for selecting model
8
- st.sidebar.header("Select a Model")
 
9
 
10
- model_option = st.sidebar.radio("Choose a task", ["Text Generation", "Text Summarization", "Sentiment Analysis"])
 
 
11
 
12
- # Load the transformer model based on selected task
13
- if model_option == "Text Generation":
14
- st.header("Text Generation")
15
- model = pipeline("text-generation", model="gpt2")
16
- user_input = st.text_area("Enter your prompt:", "Once upon a time")
17
-
18
- if st.button("Generate Text"):
19
- result = model(user_input, max_length=100, num_return_sequences=1)
20
- st.write(result[0]["generated_text"])
21
 
22
- elif model_option == "Text Summarization":
23
- st.header("Text Summarization")
24
- model = pipeline("summarization", model="facebook/bart-large-cnn")
25
- user_input = st.text_area("Enter the text to summarize:", "The quick brown fox jumps over the lazy dog.")
26
-
27
- if st.button("Summarize Text"):
28
- result = model(user_input, min_length=25, max_length=100, length_penalty=2.0, num_beams=4, early_stopping=True)
29
- st.write(result[0]["summary_text"])
30
-
31
- elif model_option == "Sentiment Analysis":
32
- st.header("Sentiment Analysis")
33
- model = pipeline("sentiment-analysis")
34
- user_input = st.text_area("Enter the text to analyze:", "I love programming!")
35
-
36
- if st.button("Analyze Sentiment"):
37
- result = model(user_input)
38
- st.write(f"Sentiment: {result[0]['label']}, Confidence: {result[0]['score']:.2f}")
 
1
  import streamlit as st
2
  from transformers import pipeline
3
 
4
+ # Initialize the summarizer pipeline
5
+ summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
6
 
7
+ def summarize_text(text):
8
+ summary = summarizer(text, max_length=150, min_length=50, do_sample=False)
9
+ return summary[0]['summary_text']
10
 
11
+ # Streamlit app layout
12
+ st.title("Text Summarizer")
13
+ st.write("This app uses Hugging Face's transformers to summarize any text you provide.")
14
 
15
+ # User input
16
+ input_text = st.text_area("Enter Text to Summarize", height=200)
 
 
 
 
 
 
 
17
 
18
+ if st.button("Summarize"):
19
+ if input_text:
20
+ with st.spinner("Summarizing..."):
21
+ summary = summarize_text(input_text)
22
+ st.subheader("Summary:")
23
+ st.write(summary)
24
+ else:
25
+ st.warning("Please enter some text to summarize.")