-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
43 lines (33 loc) · 1.45 KB
/
app.py
File metadata and controls
43 lines (33 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import streamlit as st
from transformers import pipeline
import tensorflow as tf
# Configure TensorFlow to use CPU only, avoiding any GPU-related errors
tf.config.set_visible_devices([], 'GPU')
# Load models with device set to CPU
summarizer = pipeline("summarization", model="sshleifer/distilbart-cnn-12-6", device=-1)
sentiment_analyzer = pipeline("sentiment-analysis", model="distilbert-base-uncased-finetuned-sst-2-english", device=-1)
def summarize_text(text):
"""Summarizes the input text."""
summary = summarizer(text, max_length=150, min_length=50, do_sample=False)
return summary[0]['summary_text']
def analyze_sentiment(text):
"""Analyzes the sentiment of the input text."""
sentiment = sentiment_analyzer(text)
return sentiment[0]['label']
def main():
st.title("Text Summarizer and Sentiment Analyzer")
with st.expander("Enter your text here"):
text_input = st.text_area("Text input", "", height=200, label_visibility="collapsed")
if st.button("Analyze"):
if text_input.strip():
with st.spinner("Processing..."):
summary = summarize_text(text_input)
sentiment = analyze_sentiment(text_input)
st.subheader("Summary")
st.write(summary)
st.subheader("Sentiment Analysis")
st.write(f"Sentiment: {sentiment}")
else:
st.error("Please enter some text to analyze.")
if __name__ == "__main__":
main()