|
import streamlit as st |
|
from bot import chat |
|
import nltk |
|
|
|
nltk.download('punkt') |
|
nltk.download('wordnet') |
|
|
|
|
|
st.set_page_config( |
|
page_title="MedicBot", |
|
page_icon="🩺", |
|
layout="centered", |
|
initial_sidebar_state="expanded", |
|
) |
|
|
|
|
|
def send_message(): |
|
user_input = st.session_state.user_input |
|
if user_input: |
|
st.session_state.chat_history.append(("You", user_input)) |
|
try: |
|
response = chat(user_input) |
|
if not response: |
|
raise ValueError("Received empty response") |
|
st.session_state.chat_history.append(("MedicBot", response)) |
|
except Exception as e: |
|
st.session_state.chat_history.append(("MedicBot", f"Error: {str(e)}")) |
|
st.session_state.user_input = "" |
|
|
|
|
|
def clear_chat(): |
|
st.session_state.chat_history = [] |
|
|
|
|
|
if 'chat_history' not in st.session_state: |
|
st.session_state.chat_history = [] |
|
|
|
|
|
st.title("🩺 MedicBot") |
|
st.write("Welcome to MedicBot! Your virtual medical assistant.") |
|
|
|
|
|
chat_container = st.container() |
|
with chat_container: |
|
for sender, message in st.session_state.chat_history: |
|
if sender == "You": |
|
st.markdown(f"**{sender}:** {message}", unsafe_allow_html=True) |
|
else: |
|
st.markdown(f"**<span style='color: #4CAF50;'>{sender}</span>:** {message}", unsafe_allow_html=True) |
|
|
|
|
|
st.text_input("Type your message:", key='user_input', on_change=send_message) |
|
|
|
|
|
col1, col2 = st.columns(2) |
|
with col1: |
|
st.button("Send", on_click=send_message) |
|
with col2: |
|
st.button("Clear Chat", on_click=clear_chat) |
|
|
|
|
|
|
|
st.write("Developed Gurunam Lohia") |
|
|