Aashi commited on
Commit
4cd03f2
·
verified ·
1 Parent(s): 6cc6491

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +43 -0
app.py ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ## loading all the environment variables
2
+ # from dotenv import load_dotenv
3
+ # load_dotenv()
4
+
5
+ import streamlit as st
6
+ import os
7
+ import google.generativeai as genai
8
+
9
+ genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
10
+
11
+ ## function to load Gemini Pro model and get repsonses
12
+ model=genai.GenerativeModel("gemini-pro")
13
+ chat = model.start_chat(history=[])
14
+ def get_gemini_response(question):
15
+
16
+ response=chat.send_message(question,stream=True)
17
+ return response
18
+
19
+ ##initialize our streamlit app
20
+
21
+ st.set_page_config(page_title="Q&A Demo")
22
+
23
+ st.header("Gemini LLM Application")
24
+
25
+ # Initialize session state for chat history if it doesn't exist
26
+ if 'chat_history' not in st.session_state:
27
+ st.session_state['chat_history'] = []
28
+
29
+ input=st.text_input("Input: ",key="input")
30
+ submit=st.button("Ask the question")
31
+
32
+ if submit and input:
33
+ response=get_gemini_response(input)
34
+ # Add user query and response to session state chat history
35
+ st.session_state['chat_history'].append(("You", input))
36
+ st.subheader("The Response is")
37
+ for chunk in response:
38
+ st.write(chunk.text)
39
+ st.session_state['chat_history'].append(("Bot", chunk.text))
40
+ st.subheader("The Chat History is")
41
+
42
+ for role, text in st.session_state['chat_history']:
43
+ st.write(f"{role}: {text}")