Spaces:
Sleeping
Sleeping
File size: 3,100 Bytes
fd31bf7 d7fecc1 2bd8718 fd31bf7 |
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 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
import streamlit as st
from textsummarizer.config.configuration import ConfigurationManager
from transformers import AutoTokenizer
from transformers import pipeline
class PredictionPipeline:
def __init__(self):
self.config = ConfigurationManager().get_model_evaluation_config()
def predict(self,text):
tokenizer = AutoTokenizer.from_pretrained(self.config.tokenizer_path)
gen_kwargs = {"length_penalty": 0.8, "num_beams":8, "max_length": 128}
pipe = pipeline("summarization", model=self.config.model_path,tokenizer=tokenizer)
print("Dialogue:")
print(text)
output = pipe(text, **gen_kwargs)[0]["summary_text"]
print("\nModel Summary:")
print(output)
return output
def main():
# Set page config
st.set_page_config(page_title="Dialogue Summarizer", page_icon="💬", layout="wide")
# Custom CSS to improve the appearance
st.markdown("""
<style>
.big-font {
font-size:20px !important;
font-weight: bold;
}
.result-font {
font-size:18px !important;
font-style: italic;
}
.stButton>button {
width: 100%;
height: 50px;
font-size: 20px;
}
</style>
""", unsafe_allow_html=True)
# App title and description
st.title("🤖 AI Dialogue Summarizer")
st.markdown("Transform your lengthy conversations into concise summaries with our cutting-edge AI technology.")
# Create two columns
col1, col2 = st.columns([2, 1])
with col1:
st.markdown('<p class="big-font">Input Dialogue</p>', unsafe_allow_html=True)
user_input = st.text_area("", height=300, placeholder="Paste your dialogue here...")
with col2:
st.markdown('<p class="big-font">Summary</p>', unsafe_allow_html=True)
summary_placeholder = st.empty()
# Create an instance of PredictionPipeline
predictor = PredictionPipeline()
if st.button("📝 Generate Summary"):
if user_input:
with st.spinner('Generating summary...'):
# Get the summary
summary = predictor.predict(user_input)
# Display the summary
summary_placeholder.markdown(f'<p class="result-font">{summary}</p>', unsafe_allow_html=True)
else:
st.warning("⚠️ Please enter some text to summarize.")
# Add some spacing
st.markdown("<br><br>", unsafe_allow_html=True)
# Add a section for app info
st.markdown("## About This App")
st.info("""
This AI-powered dialogue summarizer uses advanced natural language processing to distill the key points from conversations.
It's perfect for quickly understanding the essence of meetings, chats, or any form of dialogue.
**How to use:**
1. Paste your dialogue in the text area on the left.
2. Click the 'Generate Summary' button.
3. View the AI-generated summary on the right.
For best results, ensure your input is a clear dialogue or conversation.
""")
if __name__ == "__main__":
main() |