Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,41 +1,42 @@
|
|
| 1 |
-
import streamlit as st
|
| 2 |
import json
|
| 3 |
import google.generativeai as genai
|
| 4 |
|
| 5 |
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
def add_to_json(new_goal):
|
| 11 |
with open("test.json", "r") as file:
|
| 12 |
data = json.load(file)
|
| 13 |
|
| 14 |
new_item = {
|
| 15 |
-
"goal":
|
| 16 |
-
# "reminder": new_reminder
|
| 17 |
}
|
| 18 |
-
data["goals"].append(new_item)
|
| 19 |
|
| 20 |
with open("test.json", "w") as file:
|
| 21 |
json.dump(data, file, indent=4)
|
| 22 |
|
| 23 |
-
add_to_json(new_goal)
|
| 24 |
|
|
|
|
|
|
|
|
|
|
| 25 |
|
| 26 |
-
GOOGLE_API_KEY="AIzaSyCUBaL7TdISL7lRuBy19_X0-OsZfgbIgEc"
|
| 27 |
|
| 28 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
|
| 30 |
-
model = genai.GenerativeModel('gemini-pro')
|
| 31 |
|
| 32 |
-
if
|
| 33 |
-
|
| 34 |
-
Act as a personal assistant, Understand user intent from the point of view for asking a few questions. ask to know more details about {prompt}
|
| 35 |
-
:- {prompt}"""
|
| 36 |
-
completetion = model.generate_content(goals)
|
| 37 |
-
with st.chat_message("Assistant"):
|
| 38 |
-
st.write(completetion.text)
|
| 39 |
|
| 40 |
|
| 41 |
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
import json
|
| 3 |
import google.generativeai as genai
|
| 4 |
|
| 5 |
|
| 6 |
+
def add_to_json(goal): # Renamed 'new_goal' to 'goal' for clarity
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
with open("test.json", "r") as file:
|
| 8 |
data = json.load(file)
|
| 9 |
|
| 10 |
new_item = {
|
| 11 |
+
"goal": goal,
|
| 12 |
+
# "reminder": new_reminder # Remove if not used
|
| 13 |
}
|
| 14 |
+
data["goals"].append(new_item)
|
| 15 |
|
| 16 |
with open("test.json", "w") as file:
|
| 17 |
json.dump(data, file, indent=4)
|
| 18 |
|
|
|
|
| 19 |
|
| 20 |
+
GOOGLE_API_KEY = "AIzaSyCUBaL7TdISL7lRuBy19_X0-OsZfgbIgEc"
|
| 21 |
+
genai.configure(api_key=GOOGLE_API_KEY)
|
| 22 |
+
model = genai.GenerativeModel('gemini-pro')
|
| 23 |
|
|
|
|
| 24 |
|
| 25 |
+
def main(): # Wrap main logic in a function
|
| 26 |
+
if prompt := st.chat_input("Hi, how can I help you?"):
|
| 27 |
+
goal = prompt # Capture the user's goal
|
| 28 |
+
|
| 29 |
+
goals_prompt = f"""Act as a personal assistant. Understand user intent from the point of view for asking a few questions. Ask to know more details about {goal} :- {goal}"""
|
| 30 |
+
completion = model.generate_content(goals_prompt)
|
| 31 |
+
|
| 32 |
+
with st.chat_message("Assistant"):
|
| 33 |
+
st.write(completion.text)
|
| 34 |
+
|
| 35 |
+
add_to_json(goal) # Save the goal to JSON
|
| 36 |
|
|
|
|
| 37 |
|
| 38 |
+
if __name__ == "__main__":
|
| 39 |
+
main()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
|
| 41 |
|
| 42 |
|