divy131 commited on
Commit
db3fd71
·
verified ·
1 Parent(s): 7f8a6d6

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -0
app.py ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from utils import qa_pipeline
3
+
4
+ chain = qa_pipeline()
5
+
6
+ def main():
7
+ global chain
8
+ # Set the title of the web application
9
+ st.title('Indian Law Q&A Bot')
10
+
11
+ # Initialize the session state if it doesn't exist
12
+ if 'chat_log' not in st.session_state:
13
+ st.session_state.chat_log = []
14
+
15
+ # Get the user's question
16
+ user_input = st.text_input("You:")
17
+
18
+ # On user input, generate response and add to the chat log
19
+ if user_input:
20
+ # Generate the answer
21
+ bot_output = chain(user_input)
22
+ bot_output = bot_output['result']
23
+ # Add the user input and bot output to the chat log
24
+ st.session_state.chat_log.append({"User": user_input, "Bot": bot_output})
25
+ # Clear the input box
26
+ st.text_input("You:", value="", key="unique")
27
+
28
+ # Display the chat log
29
+ for exchange in st.session_state.chat_log:
30
+ st.markdown(f'**You:** {exchange["User"]}')
31
+ st.markdown(f'**Bot:** {exchange["Bot"]}')
32
+
33
+ if __name__ == "__main__":
34
+ main()