Aashi commited on
Commit
8e6851b
·
verified ·
1 Parent(s): 8c76534

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -15
app.py CHANGED
@@ -1,14 +1,9 @@
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):
@@ -16,15 +11,13 @@ def get_gemini_response(question):
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")
@@ -32,12 +25,12 @@ submit=st.button("Ask the question")
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}")
 
 
 
 
 
1
  import streamlit as st
2
  import os
3
  import google.generativeai as genai
4
 
5
  genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
6
 
 
7
  model=genai.GenerativeModel("gemini-pro")
8
  chat = model.start_chat(history=[])
9
  def get_gemini_response(question):
 
11
  response=chat.send_message(question,stream=True)
12
  return response
13
 
 
 
14
  st.set_page_config(page_title="Q&A Demo")
15
 
16
  st.header("Gemini LLM Application")
17
 
18
+ # # Initialize session state for chat history if it doesn't exist
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")
 
25
  if submit and input:
26
  response=get_gemini_response(input)
27
  # Add user query and response to session state chat history
28
+ # st.session_state['chat_history'].append(("You", input))
29
  st.subheader("The Response is")
30
  for chunk in response:
31
  st.write(chunk.text)
32
+ # st.session_state['chat_history'].append(("Bot", chunk.text))
33
+ # st.subheader("The Chat History is")
34
 
35
+ # for role, text in st.session_state['chat_history']:
36
+ # st.write(f"{role}: {text}")