File size: 1,718 Bytes
352a497
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
from dotenv import load_dotenv
load_dotenv()
import streamlit as st
import os
import pathlib
import google.generativeai as genai

os.getenv("GOOGLE_API_KEY")
genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))

# function to los the genini api model and get responses

def get_gemini_response(question):
    model =genai.GenerativeModel('gemini-pro')
    response = model.generate_content(question)
    return response.text     

  #intizlize the streamlitapp


import streamlit as st



# Display the header
st.set_page_config(page_title="DDS Q & A Demo")

# Display the header
st.header("DDS Q & A Demo using Gemini")

# Initialize session state variables if they don't exist
if 'input_text' not in st.session_state:
    st.session_state['input_text'] = ''
if 'clear_field' not in st.session_state:
    st.session_state['clear_field'] = False

# Define a function to clear the input field
def clear_input():
    st.session_state['input_text'] = ''
    st.session_state['clear_field'] = True

# Display the input field
input_text = st.text_input("Input:", value='' if st.session_state['clear_field'] else st.session_state['input_text'], on_change=lambda: update_input_text(), key="input")

# Function to update session state with the current input text
def update_input_text():
    st.session_state['input_text'] = st.session_state.input
    st.session_state['clear_field'] = False

# Submit button
submit = st.button("Ask your Question")

# Clear button
if st.button("Clear", on_click=clear_input):
    pass  # The clear_input function is called when this button is pressed

# Logic to get response
if submit:
    response = get_gemini_response(input_text)
    st.subheader("The Response is")
    st.write(response)