decodingdatascience commited on
Commit
352a497
·
verified ·
1 Parent(s): d6dd179

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +61 -0
  2. requirements.txt +3 -0
app.py ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from dotenv import load_dotenv
2
+ load_dotenv()
3
+ import streamlit as st
4
+ import os
5
+ import pathlib
6
+ import google.generativeai as genai
7
+
8
+ os.getenv("GOOGLE_API_KEY")
9
+ genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
10
+
11
+ # function to los the genini api model and get responses
12
+
13
+ def get_gemini_response(question):
14
+ model =genai.GenerativeModel('gemini-pro')
15
+ response = model.generate_content(question)
16
+ return response.text
17
+
18
+ #intizlize the streamlitapp
19
+
20
+
21
+ import streamlit as st
22
+
23
+
24
+
25
+ # Display the header
26
+ st.set_page_config(page_title="DDS Q & A Demo")
27
+
28
+ # Display the header
29
+ st.header("DDS Q & A Demo using Gemini")
30
+
31
+ # Initialize session state variables if they don't exist
32
+ if 'input_text' not in st.session_state:
33
+ st.session_state['input_text'] = ''
34
+ if 'clear_field' not in st.session_state:
35
+ st.session_state['clear_field'] = False
36
+
37
+ # Define a function to clear the input field
38
+ def clear_input():
39
+ st.session_state['input_text'] = ''
40
+ st.session_state['clear_field'] = True
41
+
42
+ # Display the input field
43
+ 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")
44
+
45
+ # Function to update session state with the current input text
46
+ def update_input_text():
47
+ st.session_state['input_text'] = st.session_state.input
48
+ st.session_state['clear_field'] = False
49
+
50
+ # Submit button
51
+ submit = st.button("Ask your Question")
52
+
53
+ # Clear button
54
+ if st.button("Clear", on_click=clear_input):
55
+ pass # The clear_input function is called when this button is pressed
56
+
57
+ # Logic to get response
58
+ if submit:
59
+ response = get_gemini_response(input_text)
60
+ st.subheader("The Response is")
61
+ st.write(response)
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ streamlit
2
+ google-generativeai
3
+ python-dotenv