Nikhil0987 commited on
Commit
56ce0fa
1 Parent(s): 92ab597

Update chat.py

Browse files
Files changed (1) hide show
  1. chat.py +44 -23
chat.py CHANGED
@@ -1,26 +1,47 @@
1
- # from transformers import pipeline, Conversation
2
- # # import streamlit_option_menu
3
- # import streamlit as st
4
-
5
- # def Chat():
6
-
7
- # query = st.chat_input("Enter your query")
8
- # convo = pipeline("conversational")
9
- # oracle = pipeline(task="zero-shot-classification", model="facebook/bart-large-mnli")
10
- # usrinput = Conversation(query)
11
- # chitchat = convo(usrinput)
12
- # ans = oracle(
13
- # query,
14
- # candidate_labels=["logout"])
15
-
16
- # if ans["scores"][0] > 0.85:
17
- # st.session_state["user"] = "visitor"
18
- # with st.chat_message("assistant"):
19
- # "You are now living in dream"
20
- # st.experimental_rerun()
21
- # else:
22
- # with st.chat_message("assistant"):
23
- # chitchat
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24
 
25
 
26
 
 
1
+ import streamlit as st
2
+ import json
3
+ import google.generativeai as genai
4
+
5
+
6
+ GOOGLE_API_KEY = "AIzaSyCUBaL7TdISL7lRuBy19_X0-OsZfgbIgEc"
7
+ genai.configure(api_key=GOOGLE_API_KEY)
8
+ model = genai.GenerativeModel('gemini-pro')
9
+
10
+ def add_to_json(goal):
11
+ try:
12
+ with open("test.json", "r") as file:
13
+ data = json.load(file)
14
+ except FileNotFoundError:
15
+ data = {"goals": []} # Create the file with an empty 'goals' list if it doesn't exist
16
+
17
+ new_item = {"Goal": goal}
18
+ data["goals"].append(new_item)
19
+
20
+ with open("test.json", "w") as file:
21
+ json.dump(data, file, indent=4)
22
+
23
+
24
+
25
+ def main():
26
+ if prompt := st.chat_input("Hi, how can I help you?"):
27
+ goals_prompt = f"""Act as a personal assistant... {prompt} """
28
+ completion = model.generate_content(goals_prompt)
29
+ add_to_json(prompt)
30
+
31
+ with st.chat_message("Assistant"):
32
+ st.write(completion.text)
33
+
34
+
35
+
36
+ # Display JSON Data
37
+ if st.button("Show JSON Data"):
38
+ with open("test.json", "r") as file:
39
+ data = json.load(file)
40
+ st.json(data) # Streamlit's way to display JSON
41
+
42
+
43
+ if __name__ == "__main__":
44
+ main()
45
 
46
 
47