pratham2002 commited on
Commit
a288892
1 Parent(s): d36c9ef

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +56 -0
  2. requirements.txt +3 -0
app.py ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from dotenv import load_dotenv
2
+ load_dotenv()
3
+
4
+ import streamlit as st
5
+ import os
6
+ import google.generativeai as genai
7
+
8
+ genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
9
+
10
+
11
+ # Now we will load Gemini Pro model and get response
12
+ model = genai.GenerativeModel("gemini-pro")
13
+ chat = model.start_chat(history=[])
14
+
15
+ def get_gemini_response(question):
16
+ response = chat.send_message(question, stream=True)
17
+ return response
18
+
19
+ # Now we will build our streamlit app
20
+ st.set_page_config(page_title="Q&A with LLM")
21
+
22
+ # st.set_page_config(
23
+ # page_title="Q&A with LLM",
24
+ # page_icon=":shark:",
25
+ # layout="centered", # Can be "wide" or "centered"
26
+ # initial_sidebar_state="auto", # Can be "auto", "expanded", "collapsed"
27
+ # background_image="./Q&A.avif", # URL or local file path
28
+ # )
29
+
30
+
31
+ st.header("LLM-based Q&A Application")
32
+
33
+ # Initializing the session state for chat history if it does not exist
34
+ if "chat_history" not in st.session_state:
35
+ st.session_state["chat_history"] = []
36
+
37
+
38
+ input = st.text_input("Input:", key="input")
39
+ submit = st.button("Ask me your Question!")
40
+
41
+ if submit and input:
42
+ response = get_gemini_response(input)
43
+ # Adding user query and Bot response to session chat history
44
+ st.session_state["chat_history"].append(("You", input))
45
+ st.subheader("Here is your Response:")
46
+ for part in response:
47
+ st.write(part.text)
48
+ st.session_state["chat_history"].append(("Bot", part.text))
49
+
50
+ st.subheader("The Chat History is: ")
51
+
52
+ for role, text in st.session_state["chat_history"]:
53
+ st.write(f"{role}:{text}")
54
+
55
+
56
+
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ streamlit
2
+ google-generativeai
3
+ python-dotenv