File size: 1,568 Bytes
52d4ec9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import streamlit as st
from langchain.prompts.few_shot import FewShotChatMessagePromptTemplate
from langchain.prompts.example_selector import LengthBasedExampleSelector

# Example dialogues + summaries
examples = [
    {
        "input": "Doctor: What symptoms are you experiencing?\nPatient: I have a sore throat and runny nose.",
        "output": "The patient reports sore throat and runny nose."
    },
    {
        "input": "Patient: I've been feeling dizzy since morning.\nDoctor: Did you eat anything unusual?\nPatient: No, just normal food.",
        "output": "The patient has dizziness but no unusual food intake."
    }
]

# Create Few-Shot Prompt Template
prompt = FewShotChatMessagePromptTemplate.from_examples(
    examples=examples,
    example_selector=LengthBasedExampleSelector(examples=examples, max_length=100),
    input_variables=["input"],
    prefix="You are a medical assistant that summarizes doctor-patient conversations. Examples:",
    suffix="Now summarize this conversation:\n{input}"
)

# Streamlit UI
st.title("πŸ’¬ Few-Shot Summarizer (No Model)")

input_text = st.text_area("Paste your medical conversation here:")

if st.button("Generate Prompt"):
    if input_text.strip():
        messages = prompt.format_messages(input=input_text)

        st.subheader("πŸ“‹ Prompt Generated:")
        for msg in messages:
            st.markdown(f"**{msg.type.upper()}**:\n```\n{msg.content}\n```")

        st.info("⚠️ This is just a prompt, not an actual summary.")
    else:
        st.warning("Please enter some conversation text.")