my-app / app.py
anurag-s-39's picture
Upload folder using huggingface_hub
f488983 verified
raw
history blame
2.51 kB
import os
import streamlit as st
from embedchain import App
os.environ["HF_HOME"] = "./models"
#! PROVIDE HUGGINGFACE TOKEN IF RUNNING OFFLINE
@st.cache_resource
def conversational_ai():
return App.from_config(config_path="./config_main.yaml")
st.title('Demo of "AI Chatbot in Law"')
st.caption(
"πŸš€ A demo of conversation AI for Dhirubhai Ambani Centre for Technology and Law (DA-CTL) made by **Anurag Shukla**, **Tanaz Pathan** under guidance of **Prof. Prasenjit Majumder**"
)
if "messages" not in st.session_state:
st.session_state.messages = [
{
"role": "assistant",
"content": """
Hi! I'm a conversational AI specializing in Indian Legal System. How may I assist you today?
""",
}
]
for message in st.session_state.messages:
with st.chat_message(message["role"]):
st.markdown(message["content"])
if prompt := st.chat_input("Disclaimer: I am still a product in developement"):
app = conversational_ai()
# if prompt.startswith("/add"):
# with st.chat_message("user"):
# st.markdown(prompt)
# st.session_state.messages.append({"role": "user", "content": prompt})
# prompt = prompt.replace("/add", "").strip()
# with st.chat_message("assistant"):
# message_placeholder = st.empty()
# message_placeholder.markdown("Adding to knowledge base...")
# app.add(prompt)
# message_placeholder.markdown(f"Added {prompt} to knowledge base!")
# st.session_state.messages.append({"role": "assistant", "content": f"Added {prompt} to knowledge base!"})
# st.stop()
with st.chat_message("user"):
st.markdown(prompt)
st.session_state.messages.append({"role": "user", "content": prompt})
with st.chat_message("assistant"):
msg_placeholder = st.empty()
msg_placeholder.markdown("Thinking...")
print("Querying the Agent.")
cntxt = app.search(prompt)
print(*cntxt, sep="\n--\n")
full_response = app.llm.query(
input_query=prompt,
contexts=[i["context"] for i in cntxt],
)
# print(f"##FULL:\n\n{full_response}")
full_response = full_response.rpartition("Answer:")[-1].strip()
print(f"#ANSWER\n\n{full_response}")
msg_placeholder.markdown(full_response)
st.session_state.messages.append(
{"role": "assistant", "content": full_response}
)