Ashik1 commited on
Commit
76fe8f6
·
verified ·
1 Parent(s): 25de023

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +45 -0
app.py ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+
8
+ genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
9
+
10
+
11
+
12
+
13
+ #function to load gemini pro model and get response
14
+ model=genai.GenerativeModel("gemini-pro")
15
+ chat=model.start_chat(history=[])
16
+
17
+
18
+ def get_gemini_response(question):
19
+ response=chat.send_message(question,stream=True)
20
+ return response
21
+
22
+
23
+ # initialize our streamlit app
24
+ st.set_page_config(page_title="Q&A")
25
+ st.header("CTET QUEARY ONLY FOR SHWETA GUPTA")
26
+
27
+ # Initiakize session state for chat history if it doesnot exist
28
+ if 'chat_history' not in st.session_state:
29
+ st.session_state['chat_history'] = []
30
+
31
+ input=st.text_input("Input:",key='inout')
32
+ submit=st.button('Ask the question')
33
+
34
+ if submit and input:
35
+ response=get_gemini_response(input)
36
+ ### Add user query and response to session chat history
37
+ st.session_state['chat_history'].append(("You",input))
38
+ st.subheader("The Response is")
39
+ for chunk in response:
40
+ st.write(chunk.text)
41
+ st.session_state['chat_history'].append(("Bot",chunk.text))
42
+ st.subheader("The Chat history is")
43
+
44
+ for role,text in st.session_state['chat_history']:
45
+ st.write(f"{role}:{text}")