File size: 1,744 Bytes
52d4ec9
50a4735
43d6abb
50a4735
52d4ec9
490b63e
 
 
 
 
 
 
 
 
 
 
793bade
50a4735
490b63e
52d4ec9
 
490b63e
 
52d4ec9
 
490b63e
 
43d6abb
490b63e
52d4ec9
490b63e
52d4ec9
490b63e
 
 
 
 
52d4ec9
490b63e
 
 
 
 
52d4ec9
490b63e
 
793bade
490b63e
52d4ec9
490b63e
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
import streamlit as st
from langchain.prompts import FewShotChatMessagePromptTemplate
from langchain.llms import HuggingFaceHub
from datasets import load_dataset

# Load the dataset
dataset = load_dataset("knkarthick/dialogsum", split="train[:1%]")  # Load a small subset of the dataset for testing

# Extract the input (dialogue) and output (summary) from the dataset
examples = [
    {
        "input": dialogue['dialogue'],  # Assuming 'dialogue' field contains the conversation text
        "output": dialogue['summary']   # Assuming 'summary' field contains the summary
    }
    for dialogue in dataset
]

# Create FewShotChatMessagePromptTemplate
example_prompt = FewShotChatMessagePromptTemplate(
    examples=examples,
    input_variables=["input"],
    prefix="You are a helpful summarizer. Here are a few examples:",
    suffix="Now summarize this: {input}"
)

# Streamlit UI
st.title("πŸ“ Text Summarizer using Few-Shot Prompt")

input_text = st.text_area("Enter the text you want to summarize:")

if st.button("Summarize"):
    if input_text.strip():
        # Format the prompt
        formatted_message = example_prompt.format(input=input_text)

        with st.expander("πŸ” Prompt Preview"):
            st.markdown(f"**Formatted Prompt:** {formatted_message}")

        # Load the model from Hugging Face (replace with your choice of model)
        model = HuggingFaceHub(
            repo_id="google/pegasus-xsum",  # You can replace with any model available in Hugging Face
            model_kwargs={"temperature": 0.7}
        )

        # Generate the summary
        summary = model(formatted_message)
        st.success("βœ… Summary:")
        st.write(summary)
    else:
        st.warning("Please enter some text!")