summarization / app.py
zoya23's picture
Create app.py
52d4ec9 verified
raw
history blame
1.57 kB
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.")