From 7ea6594fda3843b65fe1c1e8d5f7761c82880d25 Mon Sep 17 00:00:00 2001 From: Pranshav Lakhia Date: Sat, 12 Oct 2024 16:58:42 -0400 Subject: [PATCH 1/5] second try at front end because of sandip --- .idea/.gitignore | 3 +++ .idea/inspectionProfiles/profiles_settings.xml | 6 ++++++ .idea/maargdarshak.iml | 8 ++++++++ .idea/misc.xml | 7 +++++++ .idea/modules.xml | 8 ++++++++ .idea/vcs.xml | 6 ++++++ app.py | 16 ++++++++++++++++ 7 files changed, 54 insertions(+) create mode 100644 .idea/.gitignore create mode 100644 .idea/inspectionProfiles/profiles_settings.xml create mode 100644 .idea/maargdarshak.iml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml create mode 100644 app.py diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 0000000..105ce2d --- /dev/null +++ b/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/.idea/maargdarshak.iml b/.idea/maargdarshak.iml new file mode 100644 index 0000000..d0876a7 --- /dev/null +++ b/.idea/maargdarshak.iml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..9de2865 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,7 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..0e4d698 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/app.py b/app.py new file mode 100644 index 0000000..fc583dd --- /dev/null +++ b/app.py @@ -0,0 +1,16 @@ +import streamlit as st +import langchain + +st.title('Ask maargdarshak') + +if 'messages' not in st.session_state: + st.session_state.messages = [] + +for message in st.session_state.messages: + st.chat_message(message['role']).markdown(message['content']) + +prompt = st.chat_input("Ask your question here") + +if prompt: + st.chat_message('user').markdown(prompt) + st.session_state.messages.append({'role':'user', 'content':prompt}) \ No newline at end of file -- 2.45.2 From 46396b630190abc70bef14522fdcd8814c670e64 Mon Sep 17 00:00:00 2001 From: Pranshav Lakhia Date: Sat, 12 Oct 2024 20:12:09 -0400 Subject: [PATCH 2/5] only 2 files --- app.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app.py b/app.py index fc583dd..a76e1ef 100644 --- a/app.py +++ b/app.py @@ -9,8 +9,10 @@ if 'messages' not in st.session_state: for message in st.session_state.messages: st.chat_message(message['role']).markdown(message['content']) + prompt = st.chat_input("Ask your question here") if prompt: st.chat_message('user').markdown(prompt) - st.session_state.messages.append({'role':'user', 'content':prompt}) \ No newline at end of file + st.session_state.messages.append({'role':'user', 'content':prompt}) + -- 2.45.2 From e0aabc868ea9cb726c62d53a286a1f8a95a640ef Mon Sep 17 00:00:00 2001 From: Pranshav Lakhia Date: Sat, 12 Oct 2024 20:47:26 -0400 Subject: [PATCH 3/5] with llamma response --- app_response.py | 70 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 app_response.py diff --git a/app_response.py b/app_response.py new file mode 100644 index 0000000..3965031 --- /dev/null +++ b/app_response.py @@ -0,0 +1,70 @@ +import streamlit as st +import requests + + +# Streamlit App +def chatbot(): + st.title("Chatbot powered by Ollama") + + # Initialize session state for storing the chat history + if "chat_history" not in st.session_state: + st.session_state["chat_history"] = [] + + # User input section + user_input = st.text_input("You: ", "") + + if user_input: + # Get Ollama response + response = query_ollama(user_input) + # Append the conversation to the chat history + st.session_state["chat_history"].append({"role": "user", "text": user_input}) + st.session_state["chat_history"].append({"role": "bot", "text": response}) + + # Display chat history + if st.session_state["chat_history"]: + for chat in st.session_state["chat_history"]: + if chat["role"] == "user": + st.write(f"**You:** {chat['text']}") + else: + st.write(f"**Bot:** {chat['text']}") + + +# Function to query Ollama locally + +def query_ollama(prompt): + # Assuming Ollama API is running locally on port 11434 + url = "http://localhost:11434/api/generate" + payload = { + "model": "llama2", # Change model name if necessary + "prompt": prompt + } + headers = { + "Content-Type": "application/json" + } + + try: + response = requests.post(url, json=payload, headers=headers) + + # Print the status code and response text for debugging + print(f"Status Code: {response.status_code}") + print(f"Response Text: {response.text}") + + # Check if the response is successful + if response.status_code == 200: + try: + response_json = response.json() + return response_json.get("output", "Sorry, I couldn't generate a response.") + except ValueError: + st.error("The server returned an invalid response. Please check the API.") + return "Invalid response format" + else: + st.error(f"Error from API: {response.status_code}") + return f"Error: {response.status_code}" + + except requests.exceptions.RequestException as e: + st.error(f"Request failed: {e}") + return "Failed to communicate with the server." + + +if __name__ == "__main__": + chatbot() -- 2.45.2 From 1aa80a0f72bcd8e55d4e47a1e66a712155cc1174 Mon Sep 17 00:00:00 2001 From: Pranshav Lakhia Date: Sat, 12 Oct 2024 21:50:01 -0400 Subject: [PATCH 4/5] added cookies timestamp --- cookies.py | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 cookies.py diff --git a/cookies.py b/cookies.py new file mode 100644 index 0000000..57b9997 --- /dev/null +++ b/cookies.py @@ -0,0 +1,48 @@ +import streamlit as st +import time +from cookies_manager import EncryptedCookieManager + +# This should be your unique encryption key, which should be kept secure. +cookie_manager = EncryptedCookieManager( + prefix="myapp_", # Define a prefix for the cookie to avoid conflicts + password="your_secure_cookie_password" # Replace with your secure password +) + +# Initialize cookies +if not cookie_manager.ready(): + st.stop() + + +def get_user_timestamp(): + # Check if timestamp already exists in cookies + timestamp = cookie_manager.get("user_timestamp") + + if timestamp: + st.write(f"Welcome back! Your session started at: {timestamp}") + return timestamp + else: + # Generate a new timestamp in milliseconds + new_timestamp = str(int(time.time() * 1000)) + cookie_manager.set("user_timestamp", new_timestamp, max_age=3600 * 24 * 7) # Store the timestamp for 7 days + st.write(f"New session started! Your timestamp is: {new_timestamp}") + return new_timestamp + + +# Chatbot function +def chatbot(): + st.title("Chatbot with Timestamps in Cookies") + + # Retrieve or create timestamp for the user + timestamp = get_user_timestamp() + + # Display the chat prompt + user_input = st.text_input("You: ", "") + + if user_input: + # Here, instead of querying Ollama, we simulate a chatbot response + st.write(f"**Bot:** You said '{user_input}' at {timestamp}") + + +# Main +if __name__ == "__main__": + chatbot() -- 2.45.2 From d3c872ce81719538d4aafdfd5a762deff6c75716 Mon Sep 17 00:00:00 2001 From: Sandipsinh Rathod Date: Sat, 12 Oct 2024 23:27:22 -0400 Subject: [PATCH 5/5] remove .idea --- .idea/.gitignore | 3 --- .idea/inspectionProfiles/profiles_settings.xml | 6 ------ .idea/maargdarshak.iml | 8 -------- .idea/misc.xml | 7 ------- .idea/modules.xml | 8 -------- .idea/vcs.xml | 6 ------ 6 files changed, 38 deletions(-) delete mode 100644 .idea/.gitignore delete mode 100644 .idea/inspectionProfiles/profiles_settings.xml delete mode 100644 .idea/maargdarshak.iml delete mode 100644 .idea/misc.xml delete mode 100644 .idea/modules.xml delete mode 100644 .idea/vcs.xml diff --git a/.idea/.gitignore b/.idea/.gitignore deleted file mode 100644 index 26d3352..0000000 --- a/.idea/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -# Default ignored files -/shelf/ -/workspace.xml diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml deleted file mode 100644 index 105ce2d..0000000 --- a/.idea/inspectionProfiles/profiles_settings.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - \ No newline at end of file diff --git a/.idea/maargdarshak.iml b/.idea/maargdarshak.iml deleted file mode 100644 index d0876a7..0000000 --- a/.idea/maargdarshak.iml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml deleted file mode 100644 index 9de2865..0000000 --- a/.idea/misc.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml deleted file mode 100644 index 0e4d698..0000000 --- a/.idea/modules.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml deleted file mode 100644 index 35eb1dd..0000000 --- a/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file -- 2.45.2