Spaces:
Runtime error
Runtime error
| # import streamlit as st | |
| # from transformers import pipeline | |
| # # ---- Load both models ---- | |
| # @st.cache_resource | |
| # def load_summarizers(): | |
| # model_name_ft = "AIsumit123/flan-t5-base_samsum_best_ckpt" # your fine-tuned | |
| # summarizer_ft = pipeline("summarization", model=model_name_ft, tokenizer=model_name_ft) | |
| # model_name_ft2 = "philschmid/flan-t5-base-samsum" # comparison fine-tuned | |
| # summarizer_ft2 = pipeline("summarization", model=model_name_ft2, tokenizer=model_name_ft2) | |
| # model_name = "google/flan-t5-base" # pretrained | |
| # summarizer = pipeline("summarization", model=model_name, tokenizer=model_name) | |
| # return summarizer_ft, summarizer_ft2, summarizer | |
| # summarizer_ft, summarizer_ft2, summarizer = load_summarizers() | |
| # # ---- Streamlit Page Config ---- | |
| # st.set_page_config(page_title="Conversation Summarizer", page_icon="π€", layout="wide") | |
| # # ---- Custom CSS for Styling ---- | |
| # st.markdown(""" | |
| # <style> | |
| # /* Background gradient */ | |
| # .stApp { | |
| # background: linear-gradient(to bottom right, #0f2027, #203a43, #2c5364); | |
| # color: #f5f6f7; | |
| # font-family: 'Segoe UI', sans-serif; | |
| # } | |
| # /* Title */ | |
| # h1, h2, h3 { | |
| # text-align: center; | |
| # color: #fdfdfd; | |
| # } | |
| # /* Subheader accent */ | |
| # h2, h3 { | |
| # color: #e0e0e0; | |
| # } | |
| # /* Input box styling */ | |
| # textarea { | |
| # border-radius: 12px !important; | |
| # } | |
| # /* Summary cards */ | |
| # .summary-card { | |
| # background: rgba(255, 255, 255, 0.08); | |
| # border-radius: 15px; | |
| # padding: 20px; | |
| # box-shadow: 0 0 10px rgba(255,255,255,0.05); | |
| # transition: transform 0.2s ease-in-out; | |
| # } | |
| # .summary-card:hover { | |
| # transform: scale(1.02); | |
| # } | |
| # /* Section divider */ | |
| # hr { | |
| # border: none; | |
| # height: 2px; | |
| # background: linear-gradient(to right, #00c6ff, #0072ff); | |
| # margin: 30px 0; | |
| # } | |
| # /* Sidebar */ | |
| # [data-testid="stSidebar"] { | |
| # background-color: rgba(15, 25, 35, 0.95); | |
| # } | |
| # [data-testid="stSidebar"] * { | |
| # color: white !important; | |
| # } | |
| # .stButton>button { | |
| # background: linear-gradient(90deg, #00c6ff, #0072ff); | |
| # color: white; | |
| # border-radius: 8px; | |
| # font-weight: bold; | |
| # border: none; | |
| # transition: 0.3s; | |
| # } | |
| # .stButton>button:hover { | |
| # background: linear-gradient(90deg, #0072ff, #00c6ff); | |
| # transform: translateY(-1px); | |
| # } | |
| # </style> | |
| # """, unsafe_allow_html=True) | |
| # # ---- Header Section ---- | |
| # st.markdown("<h1>π€ Conversation Summarizer</h1>", unsafe_allow_html=True) | |
| # st.markdown("<h3>β¨ Compare Pretrained vs Fine-tuned FLAN-T5 Models β¨</h3>", unsafe_allow_html=True) | |
| # st.write("Paste your **conversation** below and instantly compare how fine-tuning changes summary quality.") | |
| # # ---- Text Input ---- | |
| # input_text = st.text_area( | |
| # "π¬ Conversation Input:", | |
| # height=250, | |
| # placeholder="Person A: Hi, how are you?\nPerson B: I'm good, just finished work...", | |
| # ) | |
| # # ---- Sidebar ---- | |
| # st.sidebar.header("βοΈ Summary Settings") | |
| # max_length = st.sidebar.slider("Max summary length", 30, 200, 100, step=10) | |
| # min_length = st.sidebar.slider("Min summary length", 10, 100, 30, step=5) | |
| # num_beams = st.sidebar.slider("Number of beams", 1, 8, 4) | |
| # # ---- Generate Button ---- | |
| # if st.button("β¨ Generate Summaries"): | |
| # if input_text.strip(): | |
| # with st.spinner("π§ Models are thinking..."): | |
| # base_summary = summarizer( | |
| # input_text, | |
| # max_length=max_length, | |
| # min_length=min_length, | |
| # num_beams=num_beams, | |
| # early_stopping=True, | |
| # )[0]["summary_text"] | |
| # ft_summary = summarizer_ft( | |
| # input_text, | |
| # max_length=max_length, | |
| # min_length=min_length, | |
| # num_beams=num_beams, | |
| # early_stopping=True, | |
| # )[0]["summary_text"] | |
| # ft_summary2 = summarizer_ft2( | |
| # input_text, | |
| # max_length=max_length, | |
| # min_length=min_length, | |
| # num_beams=num_beams, | |
| # early_stopping=True, | |
| # )[0]["summary_text"] | |
| # st.success("β Summaries Generated!") | |
| # # ---- Display Results ---- | |
| # st.markdown("<hr>", unsafe_allow_html=True) | |
| # col1, col2, col3 = st.columns(3) | |
| # with col1: | |
| # st.markdown('<div class="summary-card"><h3>π§ Base Model</h3><p>{}</p></div>'.format(base_summary), unsafe_allow_html=True) | |
| # with col2: | |
| # st.markdown('<div class="summary-card"><h3>π Fine-tuned (Yours)</h3><p>{}</p></div>'.format(ft_summary), unsafe_allow_html=True) | |
| # with col3: | |
| # st.markdown('<div class="summary-card"><h3>π¬ Fine-tuned (Reference)</h3><p>{}</p></div>'.format(ft_summary2), unsafe_allow_html=True) | |
| # st.markdown("<hr>", unsafe_allow_html=True) | |
| # else: | |
| # st.warning("β οΈ Please enter a conversation to summarize.") | |
| import streamlit as st | |
| from transformers import pipeline | |
| # ---- Load both models ---- | |
| def load_summarizers(): | |
| model_name_ft = "AIsumit123/flan-t5-base_samsum_best_ckpt" # your fine-tuned | |
| summarizer_ft = pipeline("summarization", model=model_name_ft, tokenizer=model_name_ft) | |
| model_name_ft2 = "philschmid/flan-t5-base-samsum" # comparison fine-tuned | |
| summarizer_ft2 = pipeline("summarization", model=model_name_ft2, tokenizer=model_name_ft2) | |
| model_name = "google/flan-t5-base" # pretrained | |
| summarizer = pipeline("summarization", model=model_name, tokenizer=model_name) | |
| return summarizer_ft, summarizer_ft2, summarizer | |
| summarizer_ft, summarizer_ft2, summarizer = load_summarizers() | |
| # ---- Streamlit Page Config ---- | |
| st.set_page_config(page_title="Conversation Summarizer", page_icon="π€", layout="wide") | |
| # ---- Custom CSS for Styling ---- | |
| st.markdown(""" | |
| <style> | |
| /* Background gradient */ | |
| .stApp { | |
| background: linear-gradient(to bottom right, #0f2027, #203a43, #2c5364); | |
| color: #f5f6f7; | |
| font-family: 'Segoe UI', sans-serif; | |
| } | |
| /* Title */ | |
| h1, h2, h3 { | |
| text-align: center; | |
| color: #fdfdfd; | |
| } | |
| /* Subheader accent */ | |
| h2, h3 { | |
| color: #e0e0e0; | |
| } | |
| /* Input box styling */ | |
| textarea { | |
| border-radius: 12px !important; | |
| } | |
| /* Summary cards */ | |
| .summary-card { | |
| background: rgba(255, 255, 255, 0.08); | |
| border-radius: 15px; | |
| padding: 20px; | |
| box-shadow: 0 0 10px rgba(255,255,255,0.05); | |
| transition: transform 0.2s ease-in-out; | |
| height: 100%; | |
| } | |
| .summary-card:hover { | |
| transform: scale(1.02); | |
| } | |
| /* Section divider */ | |
| hr { | |
| border: none; | |
| height: 2px; | |
| background: linear-gradient(to right, #00c6ff, #0072ff); | |
| margin: 30px 0; | |
| } | |
| /* Sidebar Styling - FIXED TEXT COLOR */ | |
| [data-testid="stSidebar"] { | |
| background-color: rgba(15, 25, 35, 0.95); | |
| } | |
| [data-testid="stSidebar"] * { | |
| color: white !important; | |
| } | |
| [data-testid="stSidebar"] .stSlider label, | |
| [data-testid="stSidebar"] .stSlider div, | |
| [data-testid="stSidebar"] .stSlider span { | |
| color: white !important; | |
| } | |
| /* Button styling */ | |
| .stButton>button { | |
| background: linear-gradient(90deg, #00c6ff, #0072ff); | |
| color: white; | |
| border-radius: 8px; | |
| font-weight: bold; | |
| border: none; | |
| transition: 0.3s; | |
| width: 100%; | |
| padding: 12px; | |
| } | |
| .stButton>button:hover { | |
| background: linear-gradient(90deg, #0072ff, #00c6ff); | |
| transform: translateY(-1px); | |
| box-shadow: 0 4px 12px rgba(0, 114, 255, 0.3); | |
| } | |
| /* Stats cards */ | |
| .stats-card { | |
| background: rgba(255, 255, 255, 0.05); | |
| border-radius: 10px; | |
| padding: 15px; | |
| text-align: center; | |
| margin: 5px; | |
| } | |
| </style> | |
| """, unsafe_allow_html=True) | |
| # ---- Header Section ---- | |
| st.markdown("<h1>π€ Conversation Summarizer</h1>", unsafe_allow_html=True) | |
| st.markdown("<h3>β¨ Compare Pretrained vs Fine-tuned FLAN-T5 Models β¨</h3>", unsafe_allow_html=True) | |
| st.write("Paste your **conversation** below and instantly compare how fine-tuning changes summary quality.") | |
| # ---- Example Conversations ---- | |
| example_conversations = { | |
| "Select an example...": "", | |
| "Business Meeting": """Alex: Are we ready for the client presentation tomorrow? | |
| Sarah: Almost. I just need to finalize the quarterly figures. | |
| Mike: The slides are done, but we should rehearse the demo. | |
| Alex: Let's meet at 3 PM today for a dry run. | |
| Sarah: I'll bring the updated reports. | |
| Mike: Perfect, I'll set up the conference room.""", | |
| "Casual Chat": """Tom: Hey, are you watching the game tonight? | |
| Lisa: Which one? The championship? | |
| Tom: Yeah, it starts at 8. Want to come over? | |
| Lisa: Sure! Should I bring anything? | |
| Tom: Just yourself! Maybe some snacks. | |
| Lisa: Awesome, see you at 7:30!""", | |
| "Customer Support": """Agent: Thank you for calling support. How can I help? | |
| Customer: I can't login to my account. | |
| Agent: Are you getting an error message? | |
| Customer: It says 'invalid password' but I'm sure it's correct. | |
| Agent: Let me reset your password. Check your email for a link. | |
| Customer: Got it! Thanks for your help.""" | |
| } | |
| # ---- Text Input ---- | |
| selected_example = st.selectbox("Choose an example conversation:", list(example_conversations.keys())) | |
| input_text = st.text_area( | |
| "π¬ Conversation Input:", | |
| height=250, | |
| value=example_conversations[selected_example], | |
| placeholder="Person A: Hi, how are you?\nPerson B: I'm good, just finished work...", | |
| ) | |
| # ---- Sidebar ---- | |
| st.sidebar.header("βοΈ Summary Settings") | |
| max_length = st.sidebar.slider("Max summary length", 30, 200, 100, step=10) | |
| min_length = st.sidebar.slider("Min summary length", 10, 100, 30, step=5) | |
| num_beams = st.sidebar.slider("Number of beams", 1, 8, 4, help="Higher values = better quality but slower") | |
| with st.sidebar.expander("Advanced Settings"): | |
| repetition_penalty = st.slider("Repetition penalty", 1.0, 2.0, 1.2, 0.1) | |
| length_penalty = st.slider("Length penalty", 0.5, 2.0, 1.0, 0.1) | |
| # ---- Generate Button ---- | |
| if st.button("β¨ Generate Summaries", use_container_width=True): | |
| if input_text.strip(): | |
| with st.spinner("π§ Models are thinking..."): | |
| try: | |
| base_summary = summarizer( | |
| input_text, | |
| max_length=max_length, | |
| min_length=min_length, | |
| num_beams=num_beams, | |
| early_stopping=True, | |
| repetition_penalty=repetition_penalty, | |
| length_penalty=length_penalty, | |
| )[0]["summary_text"] | |
| ft_summary = summarizer_ft( | |
| input_text, | |
| max_length=max_length, | |
| min_length=min_length, | |
| num_beams=num_beams, | |
| early_stopping=True, | |
| repetition_penalty=repetition_penalty, | |
| length_penalty=length_penalty, | |
| )[0]["summary_text"] | |
| ft_summary2 = summarizer_ft2( | |
| input_text, | |
| max_length=max_length, | |
| min_length=min_length, | |
| num_beams=num_beams, | |
| early_stopping=True, | |
| repetition_penalty=repetition_penalty, | |
| length_penalty=length_penalty, | |
| )[0]["summary_text"] | |
| st.success("β Summaries Generated!") | |
| # ---- Display Results ---- | |
| st.markdown("<hr>", unsafe_allow_html=True) | |
| # Stats row | |
| col1, col2, col3, col4 = st.columns(4) | |
| with col1: | |
| st.markdown(f'<div class="stats-card"><b>Original Length</b><br>{len(input_text.split())} words</div>', unsafe_allow_html=True) | |
| with col2: | |
| st.markdown(f'<div class="stats-card"><b>Base Summary</b><br>{len(base_summary.split())} words</div>', unsafe_allow_html=True) | |
| with col3: | |
| st.markdown(f'<div class="stats-card"><b>Your Model</b><br>{len(ft_summary.split())} words</div>', unsafe_allow_html=True) | |
| with col4: | |
| st.markdown(f'<div class="stats-card"><b>Reference Model</b><br>{len(ft_summary2.split())} words</div>', unsafe_allow_html=True) | |
| # Summary cards | |
| st.markdown("<br>", unsafe_allow_html=True) | |
| col1, col2, col3 = st.columns(3) | |
| with col1: | |
| st.markdown(f''' | |
| <div class="summary-card"> | |
| <h3>π§ Base Model</h3> | |
| <p style="color: #a8d8ea">{base_summary}</p> | |
| </div> | |
| ''', unsafe_allow_html=True) | |
| with col2: | |
| st.markdown(f''' | |
| <div class="summary-card"> | |
| <h3>π Your Fine-tuned</h3> | |
| <p style="color: #a8e6cf">{ft_summary}</p> | |
| </div> | |
| ''', unsafe_allow_html=True) | |
| with col3: | |
| st.markdown(f''' | |
| <div class="summary-card"> | |
| <h3>π¬ Reference Model</h3> | |
| <p style="color: #ffd3b6">{ft_summary2}</p> | |
| </div> | |
| ''', unsafe_allow_html=True) | |
| st.markdown("<hr>", unsafe_allow_html=True) | |
| except Exception as e: | |
| st.error(f"β Error generating summaries: {str(e)}") | |
| else: | |
| st.warning("β οΈ Please enter a conversation to summarize.") | |
| # ---- Footer ---- | |
| st.markdown("---") | |
| st.markdown( | |
| "<div style='text-align: center; color: #888;'>" | |
| "Built with β€οΈ using Streamlit & Hugging Face Transformers" | |
| "</div>", | |
| unsafe_allow_html=True | |
| ) |