Sumayyea commited on
Commit
c6312ec
·
verified ·
1 Parent(s): 95e5712

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +69 -68
app.py CHANGED
@@ -1,69 +1,70 @@
1
- import streamlit as st
2
- import google.generativeai as genai
3
-
4
- # Configure the API key
5
- GOOGLE_API_KEY = <Your API Key>
6
- genai.configure(api_key=GOOGLE_API_KEY)
7
-
8
- # Initialize the Generative Model
9
- # model = genai.GenerativeModel('gemini-pro')
10
- model = genai.GenerativeModel('gemini-1.5-flash')
11
- # Function to get response from the model
12
- def get_chatbot_response(user_input):
13
- response = model.generate_content(user_input)
14
- return response.text
15
-
16
- # Streamlit interface
17
- st.set_page_config(page_title="Simple ChatBot", layout="centered")
18
-
19
- st.title("✨ Simple ChatBot ✨")
20
- st.write("Powered by Google Generative AI")
21
-
22
- if "history" not in st.session_state:
23
- st.session_state["history"] = []
24
-
25
- # Display chat history
26
- for user_message, bot_message in st.session_state.history:
27
- st.markdown(f"""
28
- <div style="
29
- background-color: #d1d3e0;
30
- border-radius: 15px;
31
- padding: 10px 15px;
32
- margin: 5px 0;
33
- max-width: 70%;
34
- text-align: left;
35
- display: inline-block;
36
- ">
37
- <p style="margin: 0; font-size: 16px; line-height: 1.5;"><b>You:</b> {user_message} 😊</p>
38
- </div>
39
- """, unsafe_allow_html=True)
40
-
41
- st.markdown(f"""
42
- <div style="
43
- background-color: #e1ffc7;
44
- border-radius: 15px;
45
- padding: 10px 15px;
46
- margin: 5px 0;
47
- max-width: 70%;
48
- text-align: left;
49
- display: inline-block;
50
- ">
51
- <p style="margin: 0; font-size: 16px; line-height: 1.5;"><b>Bot:</b> {bot_message} 🤖</p>
52
- </div>
53
- """, unsafe_allow_html=True)
54
-
55
- # user_input = input("Enter your Prompt = ")
56
- # output = get_chatbot_response(user_input)
57
-
58
- # print(output)
59
-
60
- with st.form(key="chat_form", clear_on_submit=True):
61
- user_input = st.text_input("", max_chars=2000)
62
- submit_button = st.form_submit_button("Send")
63
-
64
- if submit_button:
65
- if user_input:
66
- response = get_chatbot_response(user_input)
67
- st.session_state.history.append((user_input, response))
68
- else:
 
69
  st.warning("Please Enter A Prompt")
 
1
+ import os
2
+ import streamlit as st
3
+ import google.generativeai as genai
4
+
5
+ # Configure the API key
6
+ GOOGLE_API_KEY = os.getenv('GOOGLE_API_KEY')
7
+ genai.configure(api_key=GOOGLE_API_KEY)
8
+
9
+ # Initialize the Generative Model
10
+ # model = genai.GenerativeModel('gemini-pro')
11
+ model = genai.GenerativeModel('gemini-1.5-flash')
12
+ # Function to get response from the model
13
+ def get_chatbot_response(user_input):
14
+ response = model.generate_content(user_input)
15
+ return response.text
16
+
17
+ # Streamlit interface
18
+ st.set_page_config(page_title="Simple ChatBot", layout="centered")
19
+
20
+ st.title("✨ Simple ChatBot ✨")
21
+ st.write("Powered by Google Generative AI")
22
+
23
+ if "history" not in st.session_state:
24
+ st.session_state["history"] = []
25
+
26
+ # Display chat history
27
+ for user_message, bot_message in st.session_state.history:
28
+ st.markdown(f"""
29
+ <div style="
30
+ background-color: #d1d3e0;
31
+ border-radius: 15px;
32
+ padding: 10px 15px;
33
+ margin: 5px 0;
34
+ max-width: 70%;
35
+ text-align: left;
36
+ display: inline-block;
37
+ ">
38
+ <p style="margin: 0; font-size: 16px; line-height: 1.5;"><b>You:</b> {user_message} 😊</p>
39
+ </div>
40
+ """, unsafe_allow_html=True)
41
+
42
+ st.markdown(f"""
43
+ <div style="
44
+ background-color: #e1ffc7;
45
+ border-radius: 15px;
46
+ padding: 10px 15px;
47
+ margin: 5px 0;
48
+ max-width: 70%;
49
+ text-align: left;
50
+ display: inline-block;
51
+ ">
52
+ <p style="margin: 0; font-size: 16px; line-height: 1.5;"><b>Bot:</b> {bot_message} 🤖</p>
53
+ </div>
54
+ """, unsafe_allow_html=True)
55
+
56
+ # user_input = input("Enter your Prompt = ")
57
+ # output = get_chatbot_response(user_input)
58
+
59
+ # print(output)
60
+
61
+ with st.form(key="chat_form", clear_on_submit=True):
62
+ user_input = st.text_input("", max_chars=2000)
63
+ submit_button = st.form_submit_button("Send")
64
+
65
+ if submit_button:
66
+ if user_input:
67
+ response = get_chatbot_response(user_input)
68
+ st.session_state.history.append((user_input, response))
69
+ else:
70
  st.warning("Please Enter A Prompt")