PriyeshVerma commited on
Commit
ad9dead
·
verified ·
1 Parent(s): a061a64

Upload 2 files

Browse files

Adding chat bot using gemini pro.

Files changed (2) hide show
  1. GeminiApp.py +40 -0
  2. requirements.txt +3 -0
GeminiApp.py ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from dotenv import load_dotenv
2
+ load_dotenv()
3
+
4
+ import streamlit as st
5
+ import os
6
+ import google.generativeai as genai
7
+ genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
8
+
9
+ model = genai.GenerativeModel("gemini-pro")
10
+ chat = model.start_chat(history=[])
11
+
12
+ def get_gemini_response(question):
13
+ response = chat.send_message(question, stream=True)
14
+ return response
15
+
16
+ st.set_page_config(page_title="Q&A Application")
17
+ st.header("Gemimni Q&A Application")
18
+
19
+ if 'chat_history' not in st.session_state:
20
+ st.session_state['chat_history'] = []
21
+
22
+ input = st.text_input("Input: ", key="input")
23
+ submit = st.button("Ask the question")
24
+
25
+ if submit and input:
26
+ response = get_gemini_response(input)
27
+ st.session_state['chat_history'].append(("You", input))
28
+ st.subheader("The response is ")
29
+ for chunk in response:
30
+ st.write(chunk.text)
31
+ st.session_state['chat_history'].append(("Bot", chunk.text))
32
+
33
+ st.subheader("The Chat history is ")
34
+
35
+ for role,text in st.session_state['chat_history']:
36
+ st.write(f"{role}:{text}")
37
+
38
+
39
+
40
+
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ python-dotenv
2
+ streamlit
3
+ google-generativeai