SalehAhmad commited on
Commit
df7d860
1 Parent(s): 93aa82a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -14
app.py CHANGED
@@ -1,27 +1,40 @@
1
  import streamlit as st
2
  from dotenv import load_dotenv
 
3
  import os
4
 
5
- # Assuming the GitHubGPT class is in the same directory
6
- from RAG import GitHubGPT
7
-
8
  # Load environment variables
9
  load_dotenv()
10
 
11
- # Initialize the chatbot object
12
  gpt_bot = GitHubGPT()
13
 
14
- # Streamlit UI
15
  st.title("GitHubGPT Chatbot")
16
  st.write("Interact with your codebase through this RAG-based chatbot!")
17
 
18
- # User input
19
- user_input = st.text_input("Ask a question about the codebase:")
 
 
 
 
 
 
20
 
21
- if st.button("Get Response"):
22
- if user_input:
23
- # Get response from the chatbot
24
- response = gpt_bot.query(user_input)
25
- st.write("Response:", response)
26
- else:
27
- st.write("Please enter a question.")
 
 
 
 
 
 
 
 
 
 
1
  import streamlit as st
2
  from dotenv import load_dotenv
3
+ from RAG import GitHubGPT # Assuming this is the class from your notebook
4
  import os
5
 
 
 
 
6
  # Load environment variables
7
  load_dotenv()
8
 
9
+ # Initialize the GitHubGPT class (adjust based on the actual class name and usage)
10
  gpt_bot = GitHubGPT()
11
 
12
+ # Set up the title and description
13
  st.title("GitHubGPT Chatbot")
14
  st.write("Interact with your codebase through this RAG-based chatbot!")
15
 
16
+ # Initialize chat history if not already done
17
+ if "messages" not in st.session_state:
18
+ st.session_state.messages = []
19
+
20
+ # Display chat messages from history
21
+ for message in st.session_state.messages:
22
+ with st.chat_message(message["role"]):
23
+ st.markdown(message["content"])
24
 
25
+ # Accept user input using the new chat_input component
26
+ if prompt := st.chat_input("Type your message here..."):
27
+ # Add user message to chat history
28
+ st.session_state.messages.append({"role": "user", "content": prompt})
29
+ # Display user message
30
+ with st.chat_message("user"):
31
+ st.markdown(prompt)
32
+
33
+ # Generate and display chatbot response
34
+ with st.chat_message("assistant"):
35
+ # Replace the following line with the actual call to your chatbot's query method
36
+ response = gpt_bot.query(prompt)
37
+ st.markdown(response)
38
+
39
+ # Add assistant response to chat history
40
+ st.session_state.messages.append({"role": "assistant", "content": response})