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

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +69 -0
  2. requirements.txt +2 -0
app.py ADDED
@@ -0,0 +1,69 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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")
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ streamlit
2
+ google-generativeai