Roberta2024 commited on
Commit
f979626
1 Parent(s): 280a54d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -29
app.py CHANGED
@@ -2,14 +2,14 @@ import streamlit as st
2
  import google.generativeai as genai
3
 
4
  # Configure Gemini API
5
- genai.configure(api_key='AIzaSyCFpgd3wBtKDYcr6k2mQcW21sxnoZ8oL90')
6
  model = genai.GenerativeModel('gemini-pro')
7
 
8
  def generate_response(user_message):
9
  try:
10
  # Use Gemini API to generate a response
11
  response = model.generate_content(user_message)
12
-
13
  # Check if the response has text
14
  if response.text:
15
  return response.text
@@ -18,33 +18,33 @@ def generate_response(user_message):
18
  except Exception as e:
19
  return f"An error occurred: {str(e)}"
20
 
21
- # Set up the Streamlit page
22
- st.set_page_config(page_title="Gemini QA System", page_icon="🤖")
 
 
23
  st.title("Gemini QA System")
24
  st.write("Ask a question and get an answer from Gemini AI.")
25
 
26
- # Create the input text area
27
- user_input = st.text_area("Enter your question here...", height=100)
28
-
29
- # Create a button to generate the response
30
- if st.button("Generate Response"):
31
- if user_input:
32
- with st.spinner("Generating response..."):
33
- response = generate_response(user_input)
34
- st.subheader("Gemini's Response:")
35
- st.write(response)
36
- else:
37
- st.warning("Please enter a question.")
38
-
39
- # Add example questions
40
- st.subheader("Example Questions:")
41
- example_questions = [
42
- "What is the capital of France?",
43
- "Explain quantum computing in simple terms."
44
- ]
45
- for question in example_questions:
46
- if st.button(question):
47
- with st.spinner("Generating response..."):
48
- response = generate_response(question)
49
- st.subheader("Gemini's Response:")
50
- st.write(response)
 
2
  import google.generativeai as genai
3
 
4
  # Configure Gemini API
5
+ genai.configure(api_key='AIzaSyBIPYXqIvI1X6unKTbuWqcVfNFCePr8_sQ')
6
  model = genai.GenerativeModel('gemini-pro')
7
 
8
  def generate_response(user_message):
9
  try:
10
  # Use Gemini API to generate a response
11
  response = model.generate_content(user_message)
12
+
13
  # Check if the response has text
14
  if response.text:
15
  return response.text
 
18
  except Exception as e:
19
  return f"An error occurred: {str(e)}"
20
 
21
+ # Initialize session state for conversation history
22
+ if 'conversation' not in st.session_state:
23
+ st.session_state.conversation = []
24
+
25
  st.title("Gemini QA System")
26
  st.write("Ask a question and get an answer from Gemini AI.")
27
 
28
+ # User input
29
+ user_message = st.text_input("Enter your question here...")
30
+
31
+ if st.button("Submit"):
32
+ if user_message:
33
+ response = generate_response(user_message)
34
+ st.session_state.conversation.append((user_message, response))
35
+
36
+ # Display conversation history
37
+ if st.session_state.conversation:
38
+ st.write("### Conversation History")
39
+ for i, (question, answer) in enumerate(st.session_state.conversation):
40
+ st.write(f"**Q{i+1}:** {question}")
41
+ st.write(f"**A{i+1}:** {answer}")
42
+
43
+ # Examples in the sidebar
44
+ st.sidebar.title("Examples")
45
+ st.sidebar.write("Click on an example to use it:")
46
+ examples = ["What is the capital of France?", "Explain quantum computing in simple terms."]
47
+ for example in examples:
48
+ if st.sidebar.button(example):
49
+ response = generate_response(example)
50
+ st.session_state.conversation.append((example, response))