KrSharangrav commited on
Commit
5628a29
Β·
1 Parent(s): e94ec88

api key inserted

Browse files
Files changed (3) hide show
  1. app.py +17 -10
  2. backup.py +22 -1
  3. requirements.txt +8 -0
app.py CHANGED
@@ -1,8 +1,17 @@
1
  import streamlit as st
2
  import pandas as pd
 
 
3
  from pymongo import MongoClient
4
  from db import insert_data_if_empty, get_mongo_client # Import functions from db.py
5
- import google.generativeai as genai # Import Generative AI library
 
 
 
 
 
 
 
6
 
7
  #### **1. Ensure Data is Inserted Before Display**
8
  insert_data_if_empty()
@@ -30,19 +39,17 @@ if st.button("Show Complete Data"):
30
  #### **4. GenAI Chatbot Interface**
31
  st.subheader("πŸ€– AI Chatbot")
32
 
33
- # Configure Generative AI model (replace `your-api-key` with actual key)
34
- genai.configure(api_key="your-api-key") # Set up your API key
35
-
36
- # Initialize model
37
- model = genai.GenerativeModel("gemini-pro")
38
-
39
  # User input for chatbot
40
  user_prompt = st.text_input("Ask AI something:")
41
 
42
  if st.button("Get AI Response"):
43
  if user_prompt:
44
- response = model.generate_content(user_prompt)
45
- st.write("### AI Response:")
46
- st.write(response.text)
 
 
 
 
47
  else:
48
  st.warning("⚠️ Please enter a question.")
 
1
  import streamlit as st
2
  import pandas as pd
3
+ import google.generativeai as genai # Import Generative AI library
4
+ import os
5
  from pymongo import MongoClient
6
  from db import insert_data_if_empty, get_mongo_client # Import functions from db.py
7
+
8
+ # πŸ”‘ Fetch API key from Hugging Face Secrets
9
+ GEMINI_API_KEY = os.getenv("gemini_api")
10
+
11
+ if GEMINI_API_KEY:
12
+ genai.configure(api_key=GEMINI_API_KEY)
13
+ else:
14
+ st.error("⚠️ Google API key is missing! Set it in Hugging Face Secrets.")
15
 
16
  #### **1. Ensure Data is Inserted Before Display**
17
  insert_data_if_empty()
 
39
  #### **4. GenAI Chatbot Interface**
40
  st.subheader("πŸ€– AI Chatbot")
41
 
 
 
 
 
 
 
42
  # User input for chatbot
43
  user_prompt = st.text_input("Ask AI something:")
44
 
45
  if st.button("Get AI Response"):
46
  if user_prompt:
47
+ try:
48
+ model = genai.GenerativeModel("gemini-pro")
49
+ response = model.generate_content(user_prompt)
50
+ st.write("### AI Response:")
51
+ st.write(response.text)
52
+ except Exception as e:
53
+ st.error(f"❌ Error: {e}")
54
  else:
55
  st.warning("⚠️ Please enter a question.")
backup.py CHANGED
@@ -2,6 +2,7 @@ import streamlit as st
2
  import pandas as pd
3
  from pymongo import MongoClient
4
  from db import insert_data_if_empty, get_mongo_client # Import functions from db.py
 
5
 
6
  #### **1. Ensure Data is Inserted Before Display**
7
  insert_data_if_empty()
@@ -10,7 +11,7 @@ insert_data_if_empty()
10
  collection = get_mongo_client()
11
 
12
  #### **3. Streamlit App to Display Data**
13
- st.title("πŸ“Š MongoDB Data Viewer")
14
 
15
  # Show first 5 rows from MongoDB
16
  st.subheader("First 5 Rows from Database")
@@ -25,3 +26,23 @@ else:
25
  if st.button("Show Complete Data"):
26
  all_data = list(collection.find({}, {"_id": 0}))
27
  st.write(pd.DataFrame(all_data))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
  import pandas as pd
3
  from pymongo import MongoClient
4
  from db import insert_data_if_empty, get_mongo_client # Import functions from db.py
5
+ import google.generativeai as genai # Import Generative AI library
6
 
7
  #### **1. Ensure Data is Inserted Before Display**
8
  insert_data_if_empty()
 
11
  collection = get_mongo_client()
12
 
13
  #### **3. Streamlit App to Display Data**
14
+ st.title("πŸ“Š MongoDB Data Viewer with AI Chatbot")
15
 
16
  # Show first 5 rows from MongoDB
17
  st.subheader("First 5 Rows from Database")
 
26
  if st.button("Show Complete Data"):
27
  all_data = list(collection.find({}, {"_id": 0}))
28
  st.write(pd.DataFrame(all_data))
29
+
30
+ #### **4. GenAI Chatbot Interface**
31
+ st.subheader("πŸ€– AI Chatbot")
32
+
33
+ # Configure Generative AI model (replace `your-api-key` with actual key)
34
+ genai.configure(api_key="secrets") # Set up your API key
35
+
36
+ # Initialize model
37
+ model = genai.GenerativeModel("gemini-pro")
38
+
39
+ # User input for chatbot
40
+ user_prompt = st.text_input("Ask AI something:")
41
+
42
+ if st.button("Get AI Response"):
43
+ if user_prompt:
44
+ response = model.generate_content(user_prompt)
45
+ st.write("### AI Response:")
46
+ st.write(response.text)
47
+ else:
48
+ st.warning("⚠️ Please enter a question.")
requirements.txt CHANGED
@@ -11,3 +11,11 @@ pydantic==1.10.13
11
  typing-extensions==4.5.0
12
  requests==2.31.0
13
  protobuf==4.25.1
 
 
 
 
 
 
 
 
 
11
  typing-extensions==4.5.0
12
  requests==2.31.0
13
  protobuf==4.25.1
14
+ generativeai==0.0.1
15
+ google-ai-generativelanguage==0.6.15
16
+ google-api-core==2.24.1
17
+ google-api-python-client==2.163.0
18
+ google-auth==2.38.0
19
+ google-auth-httplib2==0.2.0
20
+ google-generativeai==0.8.4
21
+ googleapis-common-protos==1.69.1