Spaces:
Sleeping
Sleeping
Created App
Browse files
app.py
CHANGED
@@ -1,38 +1,25 @@
|
|
1 |
import streamlit as st
|
2 |
from transformers import pipeline
|
3 |
|
4 |
-
#
|
5 |
-
|
6 |
|
7 |
-
|
8 |
-
|
|
|
9 |
|
10 |
-
|
|
|
|
|
11 |
|
12 |
-
#
|
13 |
-
|
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 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
st.
|
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.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|